问题
I'm struggling to plot a gradient color scale for each facet in facet_wrap()
independently.
Data is too big to post it here but here is my code:
ggplot(stack, aes(hour, day)) +
geom_tile(aes(fill = percent), colour = "white") +
facet_wrap(~author, ncol = 3) +
theme_minimal() +
scale_fill_distiller(palette = 'RdYlBu') +
theme(
axis.title.x = element_blank(), axis.title.y = element_blank(),
legend.position = "none",
strip.background = element_rect(fill = '#E5E6E1'),
strip.text = element_text(face = 'bold')
)
However, if I plot individually only one author, I get:
I just wanna plot each facet with its own gradient color scale, not share with the rest of the facets. Should be very simple, but I don't manage to do it. I tried adding group = author
within aes()
in geom_tile()
and ggplot()
but it wouldn't work.
回答1:
After much research, I ended up using the solution provided here that uses gridExtra
. I guess there is no easy way to do it using only ggplot
.
来源:https://stackoverflow.com/questions/59108493/independent-color-gradient-for-each-facet-in-facet-wrap-ggplot2