簡體   English   中英

錯誤:ggplot2中的stat_count()

[英]Error: stat_count() in ggplot2

在我的許多程序中,我一直使用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"作為條形圖的說明。

任何幫助將受到高度贊賞。

會話信息如下:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM