小编ato*_*res的帖子

如何在同一个 ggplot 条形图中设置 scale_fill_brewer 和 scale_fill_discrete?

我正在尝试创建条形图,但出现如下错误:

“填充”的比例已经存在。为“填充”添加另一个比例,这将替换现有比例。

我发现问题是尝试使用两个 scale_fill 函数。如果我删除其中之一(scale_fill_brewer 或 scale_fill_discrete),它就可以工作。

ggplot(df_postgres, aes(x=as.factor(language), y=total/1000, fill=type)) + 
geom_bar(stat='identity', color = 'black')+
geom_text(mapping=aes(label=ifelse(type=='A', (paste(as.character(floor(total/1000)),'K') ), '')), vjust=-0.7,color='black')+
scale_x_discrete(name="Language")+
scale_y_continuous(name="Repos (thousands)")+
scale_fill_brewer(palette='Pastel1')+
scale_fill_discrete(name="Proportion",labels=c("Language","Others"))
Run Code Online (Sandbox Code Playgroud)

我的问题是:如何设置离散选项和漂亮的调色板选项?我是 R 的新手,但找不到对这个特定错误的回应。

r ggplot2

6
推荐指数
1
解决办法
4779
查看次数

标签 统计

ggplot2 ×1

r ×1