Closed DengEr-1993 closed 1 year ago
In the new version, it should be easier to create varying fills for the facet strips. The facet functions have a strip
argument, where you can give a strip_*()
. For strip_themed()
and strip_nested()
you can vary the background fills.
library(ggplot2)
library(ggh4x)
# data<-structure(...) # omitted for brevity
ggplot(data = data, aes(Name,mean, label = Name,fill=Organ)) +
geom_bar(position="dodge2", stat="identity",width = 0.85,color="black") +
geom_errorbar(aes(ymin = mean - sd, ymax = mean + sd),position = position_dodge(0.85), width = .2) +
facet_nested(
.~Organ+Disease, scales="free",switch = "x",nest_line = TRUE,
strip = strip_nested(
background_x = elem_list_rect(fill = rainbow(15))
))+
theme_classic() +
theme(
plot.title = element_text(hjust = 0.5),
plot.margin = unit(c(5, 10, 10, 10), "mm"),
strip.background = element_rect(colour="black", fill="white"),
strip.text.x = element_text(size = 6, angle=0),
strip.placement = "outside")
I'm considering this issue resolved.
I draw a plot using ggplot2 and ggh4x with the help from @teunbrand. And it works perfect in ggh4x old version 0.1.2.1. A key function was from the author and it helped me a lot.
But several days ago, I updated some pacages including the ggh4x and now it is v 0.2.1.
Then the plot can not be produced normally with the error: Error in strip$grobs[is_strip][1] : 下标出界(subscript out of bounds)
So I think it may work if I downgrade the ggh4x version to the original version 0.1.2.1.
However the problem stil exists. I haven't changed my data so I want to know if there is something wrong with the ggh4x ?
######## here is the original question: Can I adjust the fill(color) of different label regions when using ggh4x package
Here is the code:
So I hope @teunbrand could help me. vary thankful.