0

Plotting % bloom over time and across several sites. Plot looks correct but the x-axis dates aren't in chronological order.

Code:

Blue_bloom$site <- factor(bluecrop$site, levels = c("W. Ottawa", "E. Ottawa", "W. Van Buren", "E. Van Buren"))
BC_bloom2 <- ggplot(Blue_bloom, aes(x= date, y=as.numeric(value)))+ geom_point(aes(color = site))
BC_bloom2 + theme_classic() +
  scale_color_manual(values = c("skyblue", "steelblue", "deepskyblue2", "skyblue3")) +
  geom_smooth(aes(group=1), method = "loess", se=T)+
  ylim(0,100)+
  labs(x = "date", y = "% bloom", title = "Bluecrop")`

Output:

enter image description here

Axis lists from left to right 6/11 and 6/12 before 6/3,6/5, and 6/8. Seems to be reading the first "1" in 11 and 12 as chronological...Tips??

stefan
  • 46,681
  • 5
  • 18
  • 35
  • 3
    Convert the dates to actual dates. At the moment they are strings or factors – Allan Cameron Oct 22 '20 at 18:18
  • In order for us to help you, please provide a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). For example, to produce a minimal data set, you can use `head()`, `subset()`, or the indices. Then use `dput()` to give us something that can be put in R immediately. Also, please make sure you know what to do [when someone answers your question](https://stackoverflow.com/help/someone-answers). More info can be found at Stack Overflow's [help center](https://stackoverflow.com/help). Thank you! – iamericfletcher Oct 22 '20 at 18:21
  • convert date to dates (eg with as.Date(date)) instead of strings or factors and then use scale_x_date(date_format='%m/%d') to format them – Dominik Oct 22 '20 at 18:35

0 Answers0