facet_wrap()+ ggplot2()中每个方面的独立颜色渐变 [英] Independent color gradient for each facet in facet_wrap() + ggplot2()
问题描述
我正在努力为 facet_wrap()
中的每个方面绘制渐变色标。
数据太大,无法在此处发布,但这是我的代码:
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:
我只是想要用自己的渐变色标绘制每个构面,而不是与其余构面共享。应该很简单,但是我没有做到。我尝试在 geom_tile()$ c中的
aes()
内添加 group = author
$ c>和 ggplot()
,但不起作用。
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.
推荐答案
经过大量研究,我最终使用了这里,它使用 gridExtra
。我想没有简单的方法仅使用 ggplot
。
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
.
这篇关于facet_wrap()+ ggplot2()中每个方面的独立颜色渐变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!