當使用黑色背景的ggplot2主題時,是否可以控制除顏色指南之外的指南的圖例顏色,以便事物不會以黑色繪製?如果是這樣,怎麼樣?ggplot中不是顏色指南的圖例元素的控件顏色
library(ggplot2) # needs to be 0.9.3 for this theme
data(iris) # included with ggplot2
theme_black<- function (base_size = 16, base_family = ""){
theme_minimal() %+replace%
theme(
line = element_line(colour = "white", size = 0.5, linetype = 1,
lineend = "butt"),
rect = element_rect(fill = "white",
colour = "white", size = 0.5, linetype = 1),
text = element_text(family = base_family,
face = "plain", colour = "white", size = base_size,
angle = 0, lineheight = 0.9, hjust = 0, vjust = 0),
plot.background = element_rect(colour = 'black', fill = 'black'),
plot.title = element_text(size = rel(1.2)),
panel.border = element_rect(fill = NA, colour = "white"),
panel.grid.major = element_line(colour = "grey20", size = 0.2),
panel.grid.minor = element_line(colour = "grey5", size = 0.5),
strip.background = element_rect(fill = "grey30", colour = "grey30")
)
}
ggplot(data=iris, aes(x=Sepal.Length, y=Sepal.Width, shape=Species,
colour=Petal.Length))+geom_point()+theme_black()+
scale_colour_gradient(low = "purple", high = "white")
正如你所看到的,在傳說的形狀部分的默認顏色沒有發生改變,因此它是無形的,沒有人可以知道哪個品種是:
的我現在唯一的解決方案是更改legend.background顏色,但這是浪費墨水和醜陋。
以下是部分修正:'+ guides(shape = guide_legend(override.aes = list(color =「white」)))'。不幸的是,'theme()'不能用來改變默認的點顏色。 – bdemarest
感謝您的回覆(+1)。我認爲這值得添加一個答案:我肯定會讚揚它。 – MattBagg