R 比例\颜色\手册未按预期工作
我正在使用以下代码创建条形图:R 比例\颜色\手册未按预期工作,r,charts,plot,ggplot2,R,Charts,Plot,Ggplot2,我正在使用以下代码创建条形图: temp1 <- melt(final,id='Time') p <- ggplot(temp1, aes(x=Time, y=value, fill=variable)) + geom_bar(stat="identity", position = "fill") + scale_y_continuous(labels = percent_format()) + ggtitle('Cost Structure Breakdown') +
temp1 <- melt(final,id='Time')
p <- ggplot(temp1, aes(x=Time, y=value, fill=variable)) +
geom_bar(stat="identity", position = "fill") +
scale_y_continuous(labels = percent_format()) +
ggtitle('Cost Structure Breakdown') + theme_bw() + ylab('Percent Spread') +
theme(panel.grid.minor.x = element_blank(),
panel.grid.minor.y = element_blank(),
panel.grid.major.x=element_line(color='grey90',linetype='dashed'),
panel.grid.major.y=element_line(color='grey90',linetype='dashed'),
plot.title=element_text(size=20),
axis.text=element_text(size=15),
legend.text=element_text(size=15),
legend.key=element_blank(),
legend.title=element_blank()) +
scale_color_manual(values=c("#a6cee3","#1f78b4","#b2df8a","#33a02c","#fb9a99","#e31a1c","#fdbf6f","#ff7f00","#cab2d6"))
p
temp1没有可复制的数据。一、 因此,在这里创建了一个简单的数据。我还简化了OP的代码。这里需要的是scale\u fill\u manual
mydf <- data.frame(time = letters[1:3],
variable = LETTERS[1:3],
value = runif(3, 10, 15),
stringsAsFactors = FALSE)
ggplot(mydf, aes(x=time, y=value, fill=variable)) +
geom_bar(stat="identity") +
scale_fill_manual(values=c("#a6cee3","#1f78b4","#b2df8a"))
mydf不可复制。请提供。您需要的是scale\u fill\u manual()
而不是scale\u color\u manual
。感谢您的回答,我已将数据集添加到问题中。明白了,使用了“缩放填充”手册而不是“缩放颜色”手册,并获得了所需的结果。@Patthebug很高兴这对您有所帮助。这并不能解决此问题me@robertevansanders自从我发布这篇文章以来,ggplot已经有了一些更新。你想多看看周围吗。我相信你能为你的案子找到解决办法。