我正在創建一個帶有第二個 y 軸的圖來記錄適合度的類別。我已經使用 hline 和 annotate 獲得了類別和標簽。我已經為產生圖例的箱線圖指定了一個填充。此圖例不包括注釋,但洗掉圖例也會洗掉所有注釋。有沒有辦法只洗掉注釋。見下面的代碼:
沒有傳說:
fmsft <- ggplot(Fboxm, aes(test, count))
fmsft geom_boxplot(aes(fill = test), show.legend = FALSE)
labs(x="Test", y=expression("Estimated VO"["2Max"]))
geom_hline(yintercept = 23.9, size = 1.3)
annotate("text", label = "Very Poor",
x = 7, y = 23.9)
coord_cartesian(xlim = c(0,6), clip = "off")
geom_hline(yintercept = 28.6, size = 1.3)
annotate("text", label = "Poor",
x = 7, y = 28.6)
geom_hline(yintercept = 34.6, size = 1.3)
annotate("text", label = "Fair",
x = 7, y = 34.6)
geom_hline(yintercept = 40.6, size = 1.3)
annotate("text", label = "Good",
x = 7, y = 40.6)
geom_hline(yintercept = 46.5, size = 1.3)
annotate("text", label = "Excellent",
x = 7, y = 46.5)
geom_hline(yintercept = 56, size = 1.3)
annotate("text", label = "Superior",
x = 7, y = 56)

與傳說:
fmsft <- ggplot(Fboxm, aes(test, count))
fmsft geom_boxplot(aes(fill = test))
labs(x="Test", y=expression("Estimated VO"["2Max"]))
geom_hline(yintercept = 23.9, size = 1.3)
annotate("text", label = "Very Poor",
x = 7, y = 23.9)
coord_cartesian(xlim = c(0,6), clip = "off")
geom_hline(yintercept = 28.6, size = 1.3)
annotate("text", label = "Poor",
x = 7, y = 28.6)
geom_hline(yintercept = 34.6, size = 1.3)
annotate("text", label = "Fair",
x = 7, y = 34.6)
geom_hline(yintercept = 40.6, size = 1.3)
annotate("text", label = "Good",
x = 7, y = 40.6)
geom_hline(yintercept = 46.5, size = 1.3)
annotate("text", label = "Excellent",
x = 7, y = 46.5)
geom_hline(yintercept = 56, size = 1.3)
annotate("text", label = "Superior",
x = 7, y = 56)

提前致謝!
uj5u.com熱心網友回復:
添加theme(plot.margin = unit(..., "cm"))以調整右邊距。
演示使用mtcars.
library(ggplot2)
gg <- ggplot(mtcars, aes(disp, mpg))
geom_point()
coord_cartesian(xlim = c(0, 480), clip = "off")
annotate("text", label = "quuxbar", x = 540, y = 20)
gg

gg theme(plot.margin = unit(c(0.2, 2, 0.2, 0.2), "cm"))

僅供參考,默認值:
theme_get()$plot.margin
# [1] 5.5points 5.5points 5.5points 5.5points
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/376601.html
