我只想更改圖例標題(而不是整個圖例)的背景顏色。
如果我從下面的代碼開始:
library(ggplot2)
#produce a ggplot
ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width, colour=Species))
geom_point()
我可以theme( legend.title = element_rect( fill = "lightblue", size = 0.5, linetype = "solid", colour = "black"))用來改變整個傳說的背景,這不是我所追求的。
無論如何只更改圖例標題的背景顏色?
uj5u.com熱心網友回復:
是的,使用 ggtext 包,可以做到
library(ggplot2)
library(ggtext)
ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width, colour=Species))
geom_point()
theme(legend.title = element_textbox(fill = 'red', color = 'white'))

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/527538.html
標籤:rggplot2
上一篇:ggplot2中沒有足夠的“x”或“y”觀察值用于t檢驗或wilcoxon檢驗
下一篇:如何在地圖中繪制定向網路連接
