Independent color gradient for each facet in facet_wrap() + ggplot2()

放肆的年华 提交于 2020-01-25 07:26:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!