0

I first used geom_line, and it returns the output that I want. But when using geom_smooth with curvilinear formula, each line then started from different points which make comparison between line harder. How can I fix this, so all fitted lines start from the bottom of the Y-axis?

Code:

ggplot(data = induction, 
       mapping = aes(x = time_min, y = A_state, color = treatment_p, shape = treatment_p))+ 
  geom_smooth(method = "lm", formula = y ~ poly(x, 2))+ 
  theme_classic() + 
  labs(x = "a" , y = "b%")+ 
  theme(panel.border = element_rect(colour = "black", fill = NA, size = 2), 
        legend.position = "none" )+ 
  geom_hline(yintercept = 90, linetype = "dashed", color = "black", size = 1.5)+ 
  geom_hline(yintercept = 50, linetype = "dashed", color = "black", size = 1.5)+ 
  scale_y_continuous(breaks = c(0,25,50,75,90,100))

plot using smooth: plot using smooth

plot using line: plot using line

Z.Lin
  • 28,055
  • 6
  • 54
  • 94
Alex L
  • 1
  • 1
  • 'ggplot(data = induction, mapping = aes(x = time_min, y = A_state, color = treatment_p, shape = treatment_p))+ geom_smooth(method = "lm", formula = y ~ poly(x, 2))+ theme_classic() + labs(x = "a" , y = "b%")+ theme( panel.border = element_rect(colour = "black", fill = NA, size = 2), legend.position = "none" )+ geom_hline(yintercept = 90, linetype = "dashed", color = "black", size = 1.5)+ geom_hline(yintercept = 50, linetype = "dashed", color = "black", size = 1.5)+ scale_y_continuous(breaks = c(0,25,50,75,90,100))' – Alex L Dec 08 '20 at 22:29
  • Where is 'induction' from? Please provide a reproducible example: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – william3031 Dec 09 '20 at 00:21

1 Answers1

1

It's hard to answer your question without the data, but you may want to try a higher order polynomial in the formula argument of geom_smooth(). Maybe y ~ poly(x, 4).

jmar
  • 73
  • 6