I need to generate two lines on one graph. One variable – T is plotted as the primary axis and I am looking to create a secondary axis for the variable ZP.
The dataframe is as follows:
particle_effect
AD | RT | ZP |
---|---|---|
0 | 20 | -34 |
1 | 12 | -30 |
2 | 10 | -27 |
3 | 8 | -25 |
4 | 6 | -20 |
5 | 4 | -12 |
6 | 2 | -6 |
7 | 1 | -2 |
I am trying to set the range of the T variable in the primary Y-axis from 0 to 75 and the secondary Y-axis for ZP from -50 to 0. Everything that I have tried with the sec.axis function changes both the Y-axis ranges. I might be getting something wrong but am not being able to identify it. I would appreciate the help!
particle_effect %>%
ggplot(aes(x = AD)+
geom_point(aes(y=TR),size = 2, alpha = 0.75)+
geom_point(aes(y=zp),size = 2, alpha = 0.75)+
geom_line(aes(y=TR))+
geom_line(aes(y=zp))+
scale_y_continuous(name = "T",
sec.axis = sec_axis(~.,name = "ZP"))+
theme_bw()