我目前正在繪制許多具有兩個不同 y 軸的圖形,其中第二個是對數變換的。但是,現在我正在手動設定休息時間,如果有某種方式可以自動設定休息時間,這將是一個很大的幫助,這樣看起來更好并且具有自然間距?(或者如果有更好的方法來記錄轉換第二個軸?)
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)
我當前的代碼和情節如下所示:

它來自我的資料集片段,如下所示:
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
我希望任何人都可以提供幫助,非常感謝您提前!:)
uj5u.com熱心網友回復:
使用相同的函式轉換您的左軸中斷:
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)
)

轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/529689.html
