使用 ggplot2 的 geom_bar() 进行查询 - R

6

我有一个类似以下的数据框:

mapDF <- structure(list(var = c(11L, 3L, 4L, 15L, 19L, 17L, 1L), approvals = c(10.5233545765422, 
67.9809421770218, 9.66394835013545, 2.93736399165075, 3.36787205222721, 
4.0168261757783, 1.50969267664431)), .Names = c("var", "approvals"
), row.names = c(NA, -7L), class = "data.frame")

当我尝试使用上述数据框创建条形图时,可以使用以下方法:
gplot <- ggplot(mapDF, aes(x= mapDF[1], y= mapDF[2])) + geom_bar()

我在 RStudio 中的“Plots”部分没有看到任何东西,同时收到以下信息:

Don't know how to automatically pick scale for object of type data.frame. Defaulting to continuous
Don't know how to automatically pick scale for object of type data.frame. Defaulting to continuous
Error: stat_bin requires the following missing aesthetics: x

请问有人能指出我的错误吗?


5
你是否注意到在所有你见过的ggplot代码中,人们都使用列的_名称_在aes内映射美学元素...? :) - joran
1
(你会想在 geom_bar 中使用 stat = "identity"。) - joran
1个回答

8
将 @joran 的评论整合为一个答案:
滚动显示 @joran 的评论:
ggplot(mapDF, aes(x=var, y=approvals)) + geom_bar(stat="identity")

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接