【发布时间】:2015-02-19 15:09:02
【问题描述】:
我试图让 ggplot2 将直方图的一行显示为与其他颜色不同的颜色。在这方面我是成功的;但是,当指定不同的集合时,ggplot 使用默认颜色。我确定我的代码中有错误,但我无法确定它在哪里。数据和代码如下:
创建数据
library(ggplot2)
set.seed(71185)
dist.x <- as.data.frame(round(runif(100000, min= 1.275, max= 1.725), digits=2))
colnames(dist.x) <- 'sim_con'
开始直方图
ggplot(dist.x, aes(x = sim_con)) +
geom_histogram(colour = "black", aes(fill = ifelse(dist.x$sim_con==1.55, "darkgreen", "firebrick")), binwidth = .01) +
theme(legend.position="none")
结果如下图:
我不想使用默认颜色,而是想使用“深绿色”和“耐火砖”。代码中的错误在哪里?感谢您提供的任何帮助。
【问题讨论】: