r - geom_bar用不同的填充颜色定义边框颜色

标签 r ggplot2

我想绘制一个带有geom_bar的条形图,在此我想要用黑色边框包围的独特填充颜色。但是,指令color="black"并没有被解释为“黑色”,我得到了红色边框。

library(ggplot2)
test=as.data.frame(cbind(a=c(1,1,2,3), b=1:4, c=as.character(1:4)))
ggplot(test) + geom_bar(aes(x=a, y=b, fill=c, colour="black"), stat="identity")

如何正确使用geom_bar,以便为我提供正确的黑色边框?

最佳答案

您必须将colour放在aes之外:

ggplot(test) + geom_bar(aes(x=a, y=b, fill=c), colour="black", stat="identity")

关于r - geom_bar用不同的填充颜色定义边框颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30709972/

相关文章:

r - 行频率条形图 ggplot2

r - 使用散点图和折线图向 ggplot 添加图例

r - 对 ggplot 点使用自己的符号,更改图例符号以匹配

R,dplyr : how to change the value in one column to NA based on NA values in other columns (using OR operator)

r - 为什么 RStudio 中的 ifelse 中的英语函数不起作用?

sql - 在 R 中,如何从另一个 data.frame 的一列创建具有唯一值的 data.frame?

r - 使用带有 quosures 的 select

r - 使用分区命令进行加权平均计算

R:将 geom_text() 放置在相对于图边界而不是图上的固定位置

r - 使图表在不同区域的背景颜色不同