【问题标题】:Is there a way to use my color scheme to fill a barplot using ggplot?有没有办法使用我的配色方案来使用 ggplot 填充条形图?
【发布时间】:2019-06-03 21:07:19
【问题描述】:

我正在使用 ggplot2 绘制条形图。

到目前为止,我的所有图表都按我预期的方式显示。但是,我有一个图表或一组图表没有。 我已经尝试过所有关于添加到条形图中的配色方案的 stackoverflow 问题,但似乎都没有。

我已经尝试使用我之前制作的代码,只是更改了我正在查看的变量。出于某种原因,即使有完全相同的分组,这也不起作用。

    ggplot(data = df, aes(status, fill = status)) +
      geom_bar() +
      labs(title = "Current Status", x = "status", y = "Count") +
      theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
      scale_x_discrete(labels = c("None", "current", "extra"))+
      scale_fill_mine(palette = "main", guide = "none")

但我得到的只是灰度图。 (我也无法在此处添加图表以向您展示我所看到的)

我希望有一个频率条形图,其中包含三个不同颜色的条形图。

【问题讨论】:

  • scale_fill_mine 来自哪里?你想要scale_fill_manual吗?

标签: r ggplot2 bar-chart


【解决方案1】:

欢迎来到stackoverflow。我不确定scale_fill_mine() 来自哪里。看看这个例子是否提供了一个你可以使用的方法:

library(tidyverse)

df <-
  tibble(
    status = LETTERS[1:3],
    n = c(5,15,10)
  ) %>% 
  uncount(n)


main_colors <- c("grey70", "turquoise3", "coral2")


ggplot(data = df, aes(status, fill = status)) +
  geom_bar() +
  scale_fill_manual(values = main_colors, guide = "none") +
  scale_x_discrete(labels = c("None", "current", "extra")) +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  labs(
    title = "Current Status", 
    x = "status", 
    y = "Count"
  )

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-22
    • 2014-11-22
    • 1970-01-01
    • 1970-01-01
    • 2019-10-24
    • 1970-01-01
    • 2014-08-28
    相关资源
    最近更新 更多