[英]How to globally define the aesthetics of a color bar guide in ggplot2?
我有一个 plot,它有一个带有颜色条的图例。 默认情况下,刻度线是白色的。 我可以在每个 plot 中使用guides(fill = guide_colorbar(ticks.colour = "black")
将它们更改为黑色。有没有办法以通用方式进行此修改?也许在theme_set()
或theme()
library(ggplot2)
X <- 1:3
Y <- 1:3
DF <- expand.grid(X = X,
Y = Y)
DF$Z <- 1:9
p <- ggplot(data = DF,
aes(x = X,
y = Y,
fill = Z)) +
geom_tile()
p + guides(fill = guide_colorbar(ticks.colour = "black",
frame.colour = "black"))
据我所知,刻度颜色无法全局更改,但图例周围的框架可以使用theme_set
。 创建一个自定义主题,然后将其设置为默认主题。
theme_Daniel <- function(){
theme_minimal() %+replace% #replace elements we want to change
theme(
legend.box.background = element_rect(color = "black")
)
}
theme_set(theme_Daniel())
p
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.