我有一個 ggplot,x 和 y 軸受 scale_x_continuous 限制。但是,我還想添加 x 和 y 軸標簽。這會帶來以下訊息:
'x' 的比例已經存在。為“x”添加另一個比例,這將替換現有比例。
我也在 labs 'section' 中嘗試過 ylab = 和 xlab = 但它也產生了同樣的錯誤。任何幫助將不勝感激。這是我的腳本:
MigrPlt = ggplot(Migr,aes(Distance3, `newBa`))
geom_line()
scale_x_continuous(n.breaks = 10)
xlim(0, 3800)
ylim(0,25)
labs(y= expression (paste('Ba:Ca (μmol mol'^~-1,')')), x = "Distance from Core (μm)")
geom_hline(yintercept=2.25, linetype="dashed", color = "red")
geom_vline(xintercept = 1193.9, linetype="dashed", color = "grey")
geom_vline(xintercept = 1965.5, linetype="dashed", color = "grey")
geom_vline(xintercept = 2616.9, linetype="dashed", color = "grey")
geom_vline(xintercept = 3202.8, linetype="dashed", color = "grey")
geom_vline(xintercept = 3698.9, linetype="dashed", color = "grey")
uj5u.com熱心網友回復:
xlim是limits術語 的快捷方式scale_x_XXXX,它將覆寫任何先前的 x 比例設定。如果要控制 x 資料的范圍和中斷次數,請將兩者都放在scale_x_continuous.
您可能還考慮使用coord_cartesian()來控制軸 - 主要區別在于它將保留所有輸入資料,而使用xlim或scale_x_continuous(limits = 將在任何幾何使用之前過濾掉指定范圍之外的任何資料。這通常會讓使用geom_smooth或geom_box或其他摘要幾何的用戶感到驚訝。
相比:
ggplot(mtcars, aes(wt, mpg))
geom_point()
scale_x_continuous(n.breaks = 10)

ggplot(mtcars, aes(wt, mpg))
geom_point()
scale_x_continuous(n.breaks = 10)
xlim(0, 10)
# Scale for 'x' is already present. Adding another scale for 'x', which will replace the existing scale.

ggplot(mtcars, aes(wt, mpg))
geom_point()
scale_x_continuous(n.breaks = 10, limits = c(0, 10))

uj5u.com熱心網友回復:
驚人的!感謝Jon Spring 的指導,我得到了答案!該部分的更正如下:
scale_x_continuous(n.breaks = 10, limits = c(0, 7500)) scale_y_continuous(n.breaks = 10, limits = c(0,25))
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/345869.html
下一篇:理解PCAggplot中的美學
