這比
我設法用 iris 資料集產生了類似的錯誤,其中 legend.box.background 僅部分繪制。
data(iris)
ggplot(iris) theme_classic()
geom_point(aes(x=Petal.Length, y=Sepal.Length, color=Species, size=Sepal.Width))
scale_color_manual(name=NULL, values=c("red","green","blue") ,labels=c("supersupersupersuperlong", "test2", "test3"))
theme(legend.position=c(0.1,0.75),legend.box.background=element_rect(fill="white", color="black"), legend.spacing.y=unit(0,"cm"))
更新
我注意到在我的原始示例中它與文本長度有關,所以我嘗試在一些標簽之后添加一個空格,這會稍微改變兩次繪制線條的“排列”。但是我找不到可以讓它完全消失的空白排列。任何人都知道如何手動更改 legend.box.background 的大小。如果不是,我將繪制一個幾何矩形并將其稱為退出。
uj5u.com熱心網友回復:
我認為這里的問題是(這是圖例的每個組件legend.background后面的白色矩形),部分地繪制在圍繞整個圖例的矩形周圍的線上。您可以簡單地洗掉legend.boxlegend.background
例如,您的情節從此開始:
ggplot(iris)
theme_classic()
geom_point(aes(x = Petal.Length, y = Sepal.Length, color = Species,
size = Sepal.Width))
scale_color_manual(name = NULL, values = c("red", "green", "blue"),
labels = c("supersupersupersuperlong", "test2", "test3"))
theme(legend.position = c(0.1, 0.75),
legend.box.background = element_rect(fill = "white", color = "black"),
legend.spacing.y = unit(0, "cm"))

對此:
ggplot(iris)
theme_classic()
geom_point(aes(x = Petal.Length, y = Sepal.Length, color = Species,
size = Sepal.Width))
scale_color_manual(name = NULL, values = c("red", "green", "blue"),
labels = c("supersupersupersuperlong", "test2", "test3"))
theme(legend.position = c(0.1, 0.75),
legend.background = element_blank(),
legend.box.background = element_rect(fill = "white", color = "black"),
legend.spacing.y = unit(0, "cm"))

轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/420801.html
標籤:
下一篇:在一個圖中包含3個自變數的條形圖
