ggplot“找不到功能”

时间:2018-11-06 00:02:12

标签: r ggplot2 rstudio

ggplot的新手

我正在尝试绘制如下所示的数据框结果:

 County Mean_Porosity_Percent SD_Porosity_Percent
1    Custer              52.40714            3.807763
2  Franklin              49.63394            3.642400
3     Keith              48.46000            5.461044
4      Knox                   NaN                  NA
5   Lincoln              53.38125           10.414331
6    Nemaha              52.97400            2.915541
7      Otoe              56.45143            1.949730
8    Seward              53.55875            2.641381
9   Sherman              55.66250            6.577776
10  Stanton              57.54750                  NA

ggplot代码:

ggplot(result, aes(x=County,y=Mean_Porosity_Percent), geom = "bar")

错误:找不到函数“ Mean_Porosity_Percent”

1 个答案:

答案 0 :(得分:0)

我无法解释该错误(因为列名的拼写看起来正确),但我认为您可能想使用geom_col而不是geom_bar,因为后者的功能是计数。请尝试:

ggplot(result, aes(x=County,y=Mean_Porosity_Percent) )+geom_col()

enter image description here

您应该检查str(result)的结果。我的看起来像这样:

str(result)
#-------------
'data.frame':   10 obs. of  3 variables:
 $ County               : Factor w/ 10 levels "Custer","Franklin",..: 1 2 3 4 5 6 7 8 9 10
 $ Mean_Porosity_Percent: num  52.4 49.6 48.5 NaN 53.4 ...
 $ SD_Porosity_Percent  : num  3.81 3.64 5.46 NA 10.41 ...