使用geom_bar在ggplot2中求和的问题

时间:2021-07-27 13:46:39

I am having a hard time graphing with R. I want my bar graph to aggregate the deal_count column, but it does not appear to be doing that. Not quite sure what I am missing here. The deal_count values are 'integer'. I have attempted to sum the column with different classes but no luck.

我很难用R绘图。我希望​​我的条形图聚合deal_count列,但它似乎没有这样做。不太确定我在这里缺少什么。 deal_count值为“整数”。我试图用不同的类来总结该列,但没有运气。

Also just running this

也只是运行这个

sum(funded.agvc$deal_count)

Does not yield the proper sum.....

不能产生适当的金额.....

ggplot(data=funded.agvc, aes(moved_date,deal_count)) + 
   geom_bar(colour='black', fill="#33CC00", alpha=.5, 
      size=0, width=.7,stat='identity') + xlab("Deal Funded Date") + 
   ylab("Funded Deal Count") + 
   opts(title="Deals funded since January 2011") + 
   facet_grid(grouptype~fundingstage, scales='free_y') + 
   opts(axis.text.x =theme_text(angle=45, size=5))

Here's the head

这是头脑

head(funded.agvc)
moved_date                   industry  fundingstage deal_count startup_country startup_state                  group_name   grouptype
1    2012-09  MEDICAL_DEVICES_EQUIPMENT       500k-1M          1              CA                      Boston Harbor Angels Angel Group
2    2012-10 BUSINESS_PRODUCTS_SERVICES Product Ready          1              US            MA     Launchpad Venture Group Angel Group
3    2012-07                                  Not Set          1              US                              Golden Seeds Angel Group
5    2012-09                IT_SERVICES Product Ready          1              US            NY          STAR Angel Network Angel Group
6    2012-11                     MOBILE Product Ready          1              US            TX Central Texas Angel Network Angel Group
7    2012-11                                  Not Set          2                                              NEST-TN, LLC Angel Group

And session info

和会话信息

R version 2.15.1 (2012-06-22)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

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] JavaGD_0.6-1  scales_0.2.3  rJava_0.9-3   ggplot2_0.9.3

loaded via a namespace (and not attached):
 [1] colorspace_1.1-1   dichromat_1.2-4    digest_0.5.2       grid_2.15.1        labeling_0.1       MASS_7.3-18        memoise_0.1        munsell_0.3        plyr_1.7.1        
[10] proto_0.3-9.2      RColorBrewer_1.0-5 reshape2_1.2.1     stringr_0.6.1      tools_2.15.1    

And the dput

和输入

structure(list(moved_date = c("2012-09", "2012-10", "2012-07", 
"2012-09", "2012-11", "2012-11"), industry = c("MEDICAL_DEVICES_EQUIPMENT", 
"BUSINESS_PRODUCTS_SERVICES", "", "IT_SERVICES", "MOBILE", ""
), fundingstage = c("500k-1M", "Product Ready", "Not Set", "Product Ready", 
"Product Ready", "Not Set"), deal_count = c(1L, 1L, 1L, 1L, 1L, 
2L), startup_country = c("CA", "US", "US", "US", "US", ""), startup_state = c("", 
"MA", "", "NY", "TX", ""), group_name = c("Boston Harbor Angels", 
"Launchpad Venture Group", "Golden Seeds", "STAR Angel Network", 
"Central Texas Angel Network", "NEST-TN, LLC"), grouptype = c("Angel Group", 
"Angel Group", "Angel Group", "Angel Group", "Angel Group", "Angel Group"
)), .Names = c("moved_date", "industry", "fundingstage", "deal_count", 
"startup_country", "startup_state", "group_name", "grouptype"
), row.names = c(1L, 2L, 3L, 5L, 6L, 7L), class = "data.frame")

1 个解决方案

#1


2  

This works for me if I change stat='identity' to stat='sum' (the plot is a little silly because I only used the head of the data as posted above). I get warnings about opt vs theme and theme_text vs element_text because I am using a more recent version of ggplot2 ...

如果我将stat ='identity'改为stat ='sum',这对我有用(情节有点傻,因为我只使用了上面公布的数据的头部)。我收到有关opt vs theme和theme_text vs element_text的警告,因为我使用的是更新版本的ggplot2 ...

ggplot(data=funded.agvc, aes(moved_date,deal_count)) + 
   geom_bar(colour='black', fill="#33CC00", alpha=.5, 
      size=0, width=.7,stat='sum') + xlab("Deal Funded Date") + 
   ylab("Funded Deal Count") + 
   opts(title="Deals funded since January 2011") + 
   facet_grid(grouptype~fundingstage, scales='free_y') + 
   opts(axis.text.x =theme_text(angle=45, size=5))

使用geom_bar在ggplot2中求和的问题

#1


2  

This works for me if I change stat='identity' to stat='sum' (the plot is a little silly because I only used the head of the data as posted above). I get warnings about opt vs theme and theme_text vs element_text because I am using a more recent version of ggplot2 ...

如果我将stat ='identity'改为stat ='sum',这对我有用(情节有点傻,因为我只使用了上面公布的数据的头部)。我收到有关opt vs theme和theme_text vs element_text的警告,因为我使用的是更新版本的ggplot2 ...

ggplot(data=funded.agvc, aes(moved_date,deal_count)) + 
   geom_bar(colour='black', fill="#33CC00", alpha=.5, 
      size=0, width=.7,stat='sum') + xlab("Deal Funded Date") + 
   ylab("Funded Deal Count") + 
   opts(title="Deals funded since January 2011") + 
   facet_grid(grouptype~fundingstage, scales='free_y') + 
   opts(axis.text.x =theme_text(angle=45, size=5))

使用geom_bar在ggplot2中求和的问题