Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
594 views
in Technique[技术] by (71.8m points)

r - Remove strip background keep panel border

I have the following type of plot and want to keep each strip text above the individual facet box as a "title" of sorts yet not have the default grey background and black border around the strip.background. I color it white which is close to what I want but would like the bottom edge of the strip.background or top edge of panel.border to be black.

enter image description here

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"))
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you set element_blank() for strip.background and keep element_rect(colour="black", fill = NA) for panel.border then top edge of panel.border will be black. As pointed out by @adrien, for panel.background fill should be set to NA to avoid covering of points (already set as default for theme_bw()).

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", fill = NA))

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...