如何将刻面标签(strip.background)的颜色更改为与条形图相同?

如何将刻面标签(strip.background)的颜色更改为与条形图相同?,r,ggplot2,geom-bar,facet-grid,R,Ggplot2,Geom Bar,Facet Grid,我有一个facet_网格图,总结了每个类别的基因分布,如下所示。我想更改刻面标签/strip.background(代码中带有红色框和“类别”的那一个)的颜色,使其与相应的绘图相似 如何增加条之间(而不是面之间)的间距以使其更具可读性?由于y轴标签上有大量数据(被黑匣子覆盖),因此数据被压缩,标签变得不可读 ggplot(allVFs, aes(x=Dist,y=genes)) + geom_bar(stat="identity", width = 0.75, size

我有一个
facet_网格
图,总结了每个类别的基因分布,如下所示。我想更改刻面标签/
strip.background
(代码中带有红色框和“类别”的那一个)的颜色,使其与相应的绘图相似

如何增加条之间(而不是面之间)的间距以使其更具可读性?由于y轴标签上有大量数据(被黑匣子覆盖),因此数据被压缩,标签变得不可读

ggplot(allVFs, aes(x=Dist,y=genes)) + 
  geom_bar(stat="identity", width = 0.75, size = 0.05 ) +
  facet_grid(Categories ~., scales = "free", space = "free") +
  labs( x = "Distribution (%)", y = "Genes", title = "VFs per category" ) +
  theme( strip.text = element_text( size = 8, color = "white", hjust = 0.5),
         strip.text.y = element_text(angle=0),
         strip.background = element_rect( fill = "#5675D6"), # I tried changing this but couldn't make it similar to the bar colors
         panel.background = element_rect( fill = "#efefef"),
         panel.grid.major.x = element_blank(),
         panel.grid.minor.x = element_blank(),
         panel.grid.minor.y = element_blank(),
         panel.grid.major.y = element_line( color = "#C0C0C0" ),
         panel.spacing.x = unit( 0.8, "cm" ),
         panel.spacing.y = unit( 0.5, "cm" ),
         legend.position = "none" ) +
  geom_text(aes( label = paste0( Dist, "%" ), y = genes),
            vjust = 0, size = 2, color = "black" ) +
  aes(fill = as.factor(Categories)) #This gives the color to each facet that I want to replicate with the facet labels


如有任何改进此地块的建议,将不胜感激

这在
ggplot2
中是不可能开箱即用的,但是我们可以深入
gtable
对象来获得结果

我将使用示例图和数据。但这也适用于您的示例:

库(ggplot2)

g这在
ggplot2
中是不可能开箱即用的,但是我们可以深入到
gtable
对象中以获得结果

我将使用示例图和数据。但这也适用于您的示例:

库(ggplot2)

成功了!非常感谢你,它成功了!非常感谢你这么做。