0

I understand that there is how to plot datetime variables with geom_area. I tried to convert first to a factor, then to a numeric, however i got this error every time:

Warning message: In max(ids, na.rm = TRUE) : no non-missing arguments to max; returning -Inf

If there is anyone who can help me i would really appreciate it!

My date time variable is: "POSIXct" "POSIXt" and the other numeric.

My data:

'data.frame':   96 obs. of  2 variables:
 $ Date..GMT.                : POSIXct, format: "1966-02-20 00:00:00" "1966-02-20 01:00:00" "1966-02-20 02:00:00" ...
 $ Significant.Wave.Height.m.: num  3.04 3 2.98 2.97 2.97 3 3.03 3.08 3.14 3.21 ...

My code:

df1 %>% ggplot(aes(x = Date..GMT., y = Significant.Wave.Height.m.)) +
  geom_line(size = 1, color = "#80A0C7") +
  geom_area(fill = "#80A0C7") +
  scale_y_continuous(breaks = seq(0,  7, 2),
                     limits = c(min_SigHeight, 7)) +
  scale_x_datetime(labels = date_format("%d-%b"), date_breaks = "1 day") +
  theme(panel.grid.major = element_line(size = 0.7, colour = '#D6E7EF'), 
        panel.background = element_rect(fill='white'),
        panel.grid.minor = element_blank(),
        axis.title.y = element_text(size = 20, color = "#80A0C7"),
        axis.text.y = element_text(size = 24, color = "#80A0C7"),
        panel.border = element_rect(colour = "black", fill=NA),
        axis.text.x.bottom = element_text(angle = 30, color = "black", size = 24)) +
  labs(y = expression(H[m0] (m)), x = "")
camille
  • 16,432
  • 18
  • 38
  • 60
  • Instead of the copy of the printed dataframe, could you copy the output `dput(your_data)` instead? It is a pain to reconstruct data from their print. Also, your code is lacking the initial call to `ggplot()`, so we can't see how you've mapped the data to the plot. – teunbrand Jul 09 '21 at 16:25
  • 2
    @teunbrand the `ggplot` call was there, just hidden behind the opening backticks so it was interpreted as the language for syntax highlighting. Something I've gotten into the habit of checking for when it seems like a first line is missing – camille Jul 09 '21 at 20:25
  • @camille You're absolutely right, I totally missed that. Thanks for pointing it out so that I can spot this glitch more easily in the future! – teunbrand Jul 09 '21 at 20:36

0 Answers0