I want to make a plot with two y-axes and add two linear regression lines to each group. I have seen some methods on this website, and it is easy for me to get two y-axes for the points. But I can not control the linear regression lines. The plot I want to make like this:
My data are as following:
ggplot(plotdata) + geom_point(aes(x,z),colour="green") +
geom_smooth(aes(x,y), method=lm, se=FALSE,colour="green") +
geom_point(aes(x,y*100), colour="red") +
geom_smooth(aes(x,y*100), method=lm, se=FALSE,colour="red") +
scale_y_continuous(sec.axis = sec_axis(~ . * 0.01))
I used the upper code to make this plot, but I always got the following result:
It seems like the sec.axis method cannot control the second regression line.
Could anyone give me some reminders? Tons of thanks.
This question seems to be duplicated. link