我正在嘗試將多個部分圖例(即一個情節的兩個不同特征)圖例組合到一個框中。我的真實資料是用 geom_sf() 繪制的圖,其中多邊形的填充顏色和用 geom_sf() 用線條突出顯示的特定邊框。由于這條線只是一個特征,所以單獨做一個圖例是沒有意義的。
代表
data(iris)
ggplot(iris) theme_classic()
geom_point(aes(x=Petal.Length, y=Sepal.Length, color=Species, size=Sepal.Width))
theme(legend.position=c(0.1,0.75),legend.background=element_rect(fill="white", color="black"), legend.spacing.y=unit(0,"cm"))
### Why doesn't ggplot draw a rectangle around the entire legend?
我設法減少了圖例間距,這已經使情節更干凈了,但是......
我怎樣才能完全放棄兩個單獨的圖例框并將它們組合在一個框中,以便我的情節看起來更干凈?
uj5u.com熱心網友回復:
我認為您正在尋找legend.box.background而不是legend.background:
ggplot(iris)
theme_classic()
geom_point(aes(x = Petal.Length, y = Sepal.Length,
color = Species, size = Sepal.Width))
theme(legend.position = c(0.1, 0.75),
legend.box.background = element_rect(fill = "white", color = "black"),
legend.spacing.y = unit(0,"cm"))

轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/420813.html
標籤:
