i am currenctly plotting a lot of graphs with two different y-axis, where the second one is log transformed. However, for now i am manually setting the breaks and it would be a great help if there were someway to automatically set the breaks so it looks nicer and with natural spacing? (or if there is a better way to log transform the second axis?)
coeff<-1/80000
p1<-ggplot(lf_test, aes(x=time))
geom_smooth(aes(y=normalized_gfp),size=2, span=0.3,fill = "#90d850", color = "#00BA38")
geom_smooth( aes(y=od / coeff), size=2, span=0.26,color="tomato",fill="tomato")
scale_y_continuous(limits = c(0,80000),
name = "Relative Flourescence [RFU]/[OD] ",
sec.axis = sec_axis(~ 10^(.x*coeff)-1, breaks = c(0.01,0.25,0.5,0.75,1,1.25,1.5,1.75,2.0,2.5,5.0,7.5,10.0,15.0,20.0), name = 'OD600'))
theme_grey()
theme(
axis.title.y = element_text(color = "#90d850", size=13),
axis.title.y.right = element_text(color = "tomato", size=13)
)
print(p1)
My current code and plot looks like this:
Which is derived from a snippet of my dataset that looks like this:
time media id od gfp normalized_gfp
180 21.36 IO CasA Fe_gfp 1 0.21 1839 8757.143
181 21.36 IO CasA Fe_gfp 2 0.25 4363 17452.000
182 21.36 IO CasA Fe_gfp 3 0.53 2204 4158.491
183 21.60 IO CasA Fe_gfp 1 0.22 1966 8936.364
184 21.60 IO CasA Fe_gfp 2 0.28 4517 16132.143
185 21.60 IO CasA Fe_gfp 3 0.54 2302 4262.963
186 22.08 IO CasA Fe_gfp 1 0.24 2084 8683.333
187 22.08 IO CasA Fe_gfp 2 0.31 4659 15029.032
188 22.08 IO CasA Fe_gfp 3 0.56 2395 4276.786
189 22.32 IO CasA Fe_gfp 1 0.25 2209 8836.000
190 22.32 IO CasA Fe_gfp 2 0.34 4953 14567.647
191 22.32 IO CasA Fe_gfp 3 0.57 2484 4357.895
192 22.56 IO CasA Fe_gfp 1 0.27 2323 8603.704
193 22.56 IO CasA Fe_gfp 2 0.38 5305 13960.526
194 22.56 IO CasA Fe_gfp 3 0.59 2687 4554.237
195 23.04 IO CasA Fe_gfp 1 0.27 2450 9074.074
196 23.04 IO CasA Fe_gfp 2 0.41 5588 13629.268
197 23.04 IO CasA Fe_gfp 3 0.60 2886 4810.000
198 23.28 IO CasA Fe_gfp 1 0.28 2664 9514.286
199 23.28 IO CasA Fe_gfp 2 0.44 5713 12984.091
200 23.28 IO CasA Fe_gfp 3 0.61 2993 4906.557
I hope anyone can help, thank you very much in advance! :)
CodePudding user response:
Transform your left axis breaks using the same function:
library(ggplot2)
coeff<-1/80000
ggplot(lf_test, aes(x=time))
geom_smooth(aes(y=normalized_gfp),size=2, span=0.3,fill = "#90d850", color = "#00BA38")
geom_smooth( aes(y=od / coeff), size=2, span=0.26,color="tomato",fill="tomato")
scale_y_continuous(
limits = c(0,80000),
name = "Relative Flourescence [RFU]/[OD] ",
sec.axis = sec_axis(
~ 10^(.x*coeff)-1 ,
breaks = 10^(seq(0, 8e4, by = 2e4) * coeff) - 1,
name = 'OD600'
)
)
theme_grey()
theme(
axis.title.y = element_text(color = "#90d850", size=13),
axis.title.y.right = element_text(color = "tomato", size=13)
)