【发布时间】:2014-02-09 18:06:16
【问题描述】:
我想使用 ggplot2 和 geom_bar 创建一个堆积图。
这是我的源数据:
Rank F1 F2 F3
1 500 250 50
2 400 100 30
3 300 155 100
4 200 90 10
我想要一个堆积图,其中 x 是排名,y 是 F1、F2、F3 中的值。
# Getting Source Data
sample.data <- read.csv('sample.data.csv')
# Plot Chart
c <- ggplot(sample.data, aes(x = sample.data$Rank, y = sample.data$F1))
c + geom_bar(stat = "identity")
这是我所能得到的。我不确定如何堆叠其余的字段值。
也许我的 data.frame 格式不正确?
【问题讨论】:
-
每天都会问这个问题
-
@user2209016 查看文档:docs.ggplot2.org/current/geom_bar.html。它回答了很多常见问题。
-
在我看来,上面文档的链接是开始学习 ggplot 的一个糟糕的地方。例如,知道“美学映射......如果您要覆盖绘图默认值,则只需要在图层级别设置”对初学者没有用处。我发现食谱网页更易于访问。