In ggplot2, how can I change the border of selected facets?

后端 未结 2 653
一个人的身影
一个人的身影 2021-02-08 19:57

Taking the graph from ggplot2 help pages:

ggplot(mtcars, aes(factor(cyl))) + geom_bar() + facet_grid(. ~ vs)

Is it possible to change the borde

2条回答
  •  忘了有多久
    2021-02-08 20:23

    How about filling it with a colour like this?

    dd <- data.frame(vs = c(0,1), ff = factor(0:1))
    ggplot() + geom_rect(data=dd, aes(fill=ff), 
        xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf, alpha=0.15) + 
        geom_bar(data = mtcars, aes(factor(cyl))) + facet_grid(. ~ vs) + 
        scale_fill_manual(values=c(NA, "red"), breaks=NULL)
    

    enter image description here

提交回复
热议问题