0

I am working with time monitoring and I would like to use geom-smooth to have a trend curve.

I did the following code but the curve does not appear. I guess it's a format problem for the x-axis.

Do you know how to obtain a trend curve with geom smooth? Thank you in advance for your help!I try to get trend curve with geom-smooth but it does not appear

enter image description here

ggplot(donnes,aes(x=Day,y=value,fill=measure))+ 
  geom_point() +
geom_smooth(method="loess", level=0.90)+
  facet_wrap(~measure,ncol=1, strip.position = "left", scales="free_y", labeller = as_labeller(c(Coelenterazine = "Coelenterazine\ncontent (ng/g)", Luciferase = "Luciferase activity\n(Mq/g.s)",LightKCl= "Luminous capabilities\nwith KCl stimulation\n(Mq/g)",LightAch="Luminous capabilities\nwith acethylcholine\n(Mq/g)")))+
  geom_vline(xintercept = 9.5, linetype="dotted", color = "black", size=1)+
  geom_vline(xintercept = 13.5, linetype="dotted", color = "black", size=1)+
  ylab(NULL) +
  labs(x="Number of days in captivity")+
  scale_x_discrete(expand = c(0,.6),limits = c("D0","D30","D60","D90","D120","D150","D180","D210","D240","D247","D254","D261","D268","D298","D328","D358","D388","D418","D448","D478"),labels=c("D0","D30","D60","D90","D120","D150","D180","D210","D240","D247","D254","D261","D268","D298","D328","D358","D388","D418","D448","D478"))+
  labs(caption = "Evolution of coelenterazine content from August 2021 to December 2022")+
  scale_color_manual(name = NULL, values = c("green4", "red4", "grey5","grey23"))+
  scale_fill_manual(values = c("Coelenterazine"="green3","Luciferase"="red2","LightKCl"="grey17","LightAch"="gray72"),
                    name = "Measurements",
                    labels = c("Coelenterazine content","Luciferase activity","Light emission with KCl","Light emission with acethylcholine"))+
  theme_bw()+
  theme(legend.position = "none", 
        panel.border = element_blank(),
        strip.background = element_blank(),
        strip.placement = "outside",
        strip.text.x = element_blank(),
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        axis.line = element_line(size = 0.5, linetype = "solid", colour = "black"),
        axis.title.x = element_text(color = "black", size = 12,family = "Tahoma"),
        axis.text.x = element_text(color="black",size=10,family = "Tahoma",angle = -40, hjust=0.1),
        axis.text.y = element_text(color="black",size=10,family = "Tahoma"))
stefan
  • 90,330
  • 6
  • 25
  • 51
  • Try with `geom_smooth(aes(group = 1), method="loess", level=0.90)`. In case of a discrete x variable or scale you have to explicitly set the group aes for `geom_smooth`, `geom_line`, ... See e.g. https://stackoverflow.com/questions/68684590/geom-smooth-doesnt-plot-on-ggplot2 – stefan Sep 01 '23 at 12:42

0 Answers0