我想洗掉下圖(紅色矩形)圖例中的空間。如何洗掉這個空間?
數字

代碼
ggplot(C, aes(x = sigma, y = value, group=name))
geom_line(aes(linetype=name))
scale_linetype_manual(values=c("solid", "twodash", "dotted"))
theme_minimal()
theme_classic()
theme(legend.position = c(0.15, 0.85),
legend.background = element_rect(fill="white",
size=0.5,
linetype="solid",
colour ="gray"),
text = element_text(size=20),
legend.text = element_text(size=20),
axis.title=element_text(size=20),
legend.title = element_blank(),
panel.grid.major.y = element_line(),
panel.grid.minor.y = element_line())
uj5u.com熱心網友回復:
您可以通過設定洗掉圖例條目和背景框之間的空白區域legend.spacing.y = unit(0, "pt")。如果這仍然是太多的空白,您可以嘗試使用負值或通過legend.margin以下方式減少頂部邊距:
使用ggplot2::economics_long作為示例資料:
library(ggplot2)
ggplot(subset(economics_long, variable != "pop"), aes(x = date, y = value))
geom_line(aes(linetype=variable))
scale_linetype_manual(values=c("solid", "twodash", "dotted", "solid", "twodash"))
theme_classic()
theme(legend.position = c(0.15, 0.85),
legend.background = element_rect(fill="white",
size=0.5,
linetype="solid",
colour ="gray"),
legend.spacing.y = unit(0, "pt"),
text = element_text(size=20),
legend.text = element_text(size=20),
axis.title=element_text(size=20),
legend.title = element_blank(),
panel.grid.major.y = element_line(),
panel.grid.minor.y = element_line())

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