dplyr和ggplot2有关汇总数据的问题

时间:2018-06-27 02:18:15

标签: r ggplot2 dplyr

尝试使用dplyr和ggplot2汇总数据时遇到问题。我有一个导入的数据集(excel文件):

df<-read.xlsx('sample.xlsx', sheet = 1)

带有数据样本

        date  user          vert  aff        browser clicks age    rpc installs  revenue   Week    Month   Year
1 2017-10-25 2017-10-25   maps_1  appfocus1  Chrome     13   0 0.4436       37   5.7668     43      10   2017
2 2017-10-25 2017-10-25   maps_1  appfocus1  Chrome   1140   0 0.4436     2914 505.7040     43      10   2017
3 2017-10-25 2017-10-25     maps appfocus84  Chrome   2189   0 0.4436     7543 971.0404     43      10   2017
4 2017-10-25 2017-10-25   maps_1  appfocus1 Firefox      1   0 0.4436        6   0.4436     43      10   2017
5 2017-10-25 2017-10-25   maps_1  appfocus1 Firefox    123   0 0.4436      170  54.5628     43      10   2017
6 2017-10-25 2017-10-25     maps appfocus84 Firefox    331   0 0.4436      497 146.8316     43      10   2017
         source
1 googlepartner
2        search
3          NULL
4 googlepartner
5        search
6          NULL

下面的代码采用“关联”列,并基于该列生成两个字段的总和。然后,我通过“会员”创建一个计算字段:

UC10 <- filter(df, UCMonth == 10)

UC101 <- UC10 %>% group_by(affiliate) %>% 
  summarise_at(vars(revenue,installs),sum)%>%
  mutate(RPI = revenue/installs) 

并获取以下数据:

# A tibble: 2 x 4
  affiliate  revenue installs    RPI
  <chr>        <dbl>    <dbl>  <dbl>
1 appfocus1   53603.   809580 0.0662
2 appfocus84 174479.  2768181 0.0630

然后我尝试使用ggplot2按会员绘制总RPI:

gcor <- ggplot(UC101, aes(x = affiliate, y = RPI)) +
  geom_boxplot(color = "dark red")

我的问题是图形的输出。查看图表时,出现以下错误:

enter image description here

任何人都可以帮助理解为什么它没有显示完整的箱形图吗?这确实是我第一次同时使用dplyr和ggplot2,因此将不胜感激。

0 个答案:

没有答案