0

I am having an issue with ggplot. My geom_smooth() curve is the same for three data sets. I have been playing with the data for hours now and I am still stumped.

Any ideas?

code:

COVID <- StatCovid <- read_excel("StatCovid.xlsx", sheet = "Organized")

United_States <- COVID %>% group_by(United_States) %>% select(dateRep, United_States)
France <- COVID %>% group_by(France) %>% select(dateRep, France)
India <- COVID %>% group_by(India)%>% select(dateRep, India)

ggplot(data = COVID, mapping = aes(x= ymd(dateRep), y= COVID$United_States)) + 
geom_point(color = "red") + 
geom_point(data = COVID, aes(x= ymd(dateRep), y= COVID$France), color= "blue") +
geom_point(data = COVID, aes(x= ymd(dateRep), y= COVID$India), color = "green") +
geom_smooth(data = United_States, aes(color = "United_States"),se = F)+
geom_smooth(data = France, aes(color = "France"),se = F)+
geom_smooth(data = India, aes(color = "India"),se = F)+
scale_color_manual(name = "Country", values = c(United_States = "red", France = "blue", India ="green"))+
theme_classic() + xlab(NULL) +ylab("Number of New Cases Found")+ labs(title = "Spread of COVID-19 as a result of Holiday Travel")

The end goal of my chart is to have a shaded region with a given width around the same time as holidays to see if covid spread more during the holidays.

This is just showing how the smooth geom is the same. enter image description here

reference with 1 enter image description here

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
  • 3
    Welcome to Stack Overflow! Could you make your problem reproducible by sharing a sample of your data so others can help (please do not use `str()`, `head()` or screenshot)? You can use the [`reprex`](https://reprex.tidyverse.org/articles/articles/magic-reprex.html) and [`datapasta`](https://cran.r-project.org/web/packages/datapasta/vignettes/how-to-datapasta.html) packages to assist you with that. See also [Help me Help you](https://speakerdeck.com/jennybc/reprex-help-me-help-you?slide=5) & [How to make a great R reproducible example?](https://stackoverflow.com/q/5963269) – Tung Mar 22 '21 at 06:53
  • 1
    You haven't definied any aesthethics mappings for your geom_smooths, so they use the aes from your ggplot call. Try adding e.g. aes(x= ymd(dateRep), y= COVID$France) – MånsT Mar 22 '21 at 07:41
  • 3
    You will probably find ggplot easier if you reshape the data with `pivot_longer ` first – Richard Telford Mar 22 '21 at 08:52

0 Answers0