我有以下类型的情节,并希望将每个条形文字保留在各个方面框的上方作为各种各样的“标题”,但没有strip.background
周围的默认灰色背景和黑色边框。我将其颜色设置为接近我想要的颜色,但希望strip.background
的底边或panel.border
的上边缘为黑色。
library(ggplot2)
ggplot(mtcars, aes(mpg, hp)) + geom_point() +
facet_wrap(~carb, ncol = 3) + theme_bw() +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
strip.background = element_rect(colour="white", fill="white"),
panel.border = element_rect(colour = "black"))
答案 0 :(得分:38)
如果您为element_blank()
设置strip.background
并为element_rect(colour="black")
设置panel.border
,那么panel.border
的上边缘将为黑色。
ggplot(mtcars, aes(mpg, hp)) + geom_point() +
facet_wrap(~carb, ncol = 3) + theme_bw() +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
strip.background = element_blank(),
panel.border = element_rect(colour = "black"))
答案 1 :(得分:9)
Setting panel.border
might cover your graph unless you also add fill=NA
to panel.border
:
theme(panel.border = element_rect(fill = NA, colour = "black"))
One can also use:
theme(panel.background = element_rect(fill = NA, color = "black")
source (section "Panel Attributes")
答案 2 :(得分:3)
您可以尝试:
strip.background = element_rect(colour=NA, fill=NA),
panel.border = element_rect(fill = NA, color = "black"))