- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的许多程序中,我一直使用 ggplot2 来渲染图表。我已将它们加载到shinyapps.io 上,并且它们工作得非常好。但是,当我尝试在我的计算机上运行该程序时,出现以下错误:
Error : stat_count() must not be used with a y aesthetic.
示例代码如下:
ggplot(hashtg, aes(x=reorder(hashtag, Freq), y = Freq, fill = hashtag)) + geom_bar(stat="identity") +
geom_bar(width = 0.4) + xlab("Hashtags Used") + ylab("Number of responses") +
geom_text(aes(label=Freq), hjust = 1, colour = "white" )
实际代码有很多条形图参数,例如标题、主题和注释,但我想它们不会妨碍输出。我正在使用聚合数据,其中代码中的 Freq
是特定术语的频率。当我搜索帮助时,我重复获取使用 stat = "identity"
绘制条形图的说明。
任何帮助将不胜感激。
session 信息如下:
R version 3.2.0 (2015-04-16)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.10.3 (Yosemite)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] wordcloud_2.5 RColorBrewer_1.1-2 SnowballC_0.5.1 ggplot2_2.0.0 plyr_1.8.3
[6] chron_2.3-47 RCurl_1.95-4.7 bitops_1.0-6 ROAuth_0.9.6 RJSONIO_1.3-0
[11] twitteR_1.1.9 base64enc_0.1-3 tm_0.6-2 NLP_0.1-8 stringr_1.0.0
[16] shinydashboard_0.5.1 shinyIncubator_0.2.2 shiny_0.12.2
loaded via a namespace (and not attached):
[1] Rcpp_0.12.1 tools_3.2.0 digest_0.6.8 bit_1.1-12 jsonlite_0.9.17 gtable_0.1.2
[7] DBI_0.3.1 rstudioapi_0.3.1 curl_0.9.3 parallel_3.2.0 httr_1.0.0 bit64_0.9-5
[13] grid_3.2.0 R6_2.1.1 magrittr_1.5 scales_0.3.0 htmltools_0.2.6 colorspace_1.2-6
[19] mime_0.4 xtable_1.7-4 httpuv_1.3.3 labeling_0.3 stringi_0.5-5 munsell_0.4.2
[25] slam_0.1-32 rjson_0.2.15 rstudio_0.98.1103
重申一下,相同的代码在shinyapps.io 中运行没有任何问题。
最佳答案
我找到了这个链接(http://tutorials.iq.harvard.edu/R/Rgraphics/Rgraphics.html)以及此错误的解决方案。
您尝试使用 geom_bar()
进行汇总的列已被汇总。您需要将 stat=stat_count
(geom_bar()
中的默认值)更改为identity。
+ geom_bar(stat="identity")
或者,您可以使用 geom_col
代替。
关于r - 错误: stat_count() in ggplot2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34963138/
在我的许多程序中,我一直使用 ggplot2 来渲染图表。我已将它们加载到shinyapps.io 上,并且它们工作得非常好。但是,当我尝试在我的计算机上运行该程序时,出现以下错误: Error :
出于某种原因,我似乎无法使用 stat_count 向 ggplot 添加正确的比例标签。下面的代码返回显示所有类别 100% 的标签,即使我使用的是 ..prop..。我应该使用其他东西代替 sta
我试图绘制一个条形图,显示不同植物油的脂肪成分。我尝试在 y 轴上绘制油的类型,在 x 轴上绘制脂肪量,以便将每种类型的脂肪并排放置。 尝试的代码: ggplot(fats, aes(x=Fats,
This question already has answers here: R ggplot2: stat_count() must not be used with a y aesthetic
我在绘制条形图时遇到此错误,并且无法摆脱它,我已经尝试了 qplot 和 ggplot 但仍然是相同的错误。 以下是我的代码: library(dplyr) library(ggplot2) #
我是一名优秀的程序员,十分优秀!