小编pib*_*o95的帖子

facet_wrap() + ggplot2() 中每个面的独立颜色渐变

我正在努力独立地为每个方面绘制渐变色标facet_wrap()。数据太大,无法在这里发布,但这是我的代码:

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')
  )
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

然而,如果我只单独绘制一位作者,我会得到:

在此输入图像描述

我只想用自己的渐变色标绘制每个面,而不是与其他面共享。应该很简单,但我没能做到。我尝试添加group = authorinaes()和但它不起作用geom_tile()。ggplot()

gradient r colors ggplot2 facet-wrap

5
推荐指数
1
解决办法
2324
查看次数

dplyr + ggplot2。在同一管道内的 scale_x_continuous() 中使用使用 dplyr 计算的列

有没有办法在同一管道中使用 ggplot2 的 scale_x_continuous() 中使用 dplyr 计算的列?

p2 <- chat %>%
        count(author) %>%
        ggplot(aes(x = reorder(author, n), y = n, fill = n)) +
          geom_bar(stat = "identity") +
          coord_flip() +
          theme_classic() +
          scale_fill_viridis() +
          scale_x_continuous(breaks = seq(0, **max(n)**, by = 250))
          theme(
            axis.title.x = element_blank(), axis.title.y = element_blank(),
            legend.position = "none",
            plot.title = element_text(size = 13, face = "bold", hjust = 0.5),
            plot.subtitle = element_text(color = '#666664', size = 10, hjust = 0.5))
Run Code Online (Sandbox Code Playgroud)

基本上,我正在计算不同作者(因子列)出现在数据框中的次数。但是,R 不允许我使用n在 scale_x_continuous 中(这是 count() …

pipeline r ggplot2 dplyr

0
推荐指数
1
解决办法
143
查看次数

标签 统计

ggplot2 ×2

r ×2

colors ×1

dplyr ×1

facet-wrap ×1

gradient ×1

pipeline ×1