气泡图创建

时间:2016-07-28 18:04:15

标签: r

如果我有数据集

       Class        Percent Attended            Percent Participated
         3                 .8                             .6
         3                 .5                              .4
         2                 .9                             .5
         7                 .92                            .8

依此类推,我试图创建一个气泡图,其中显示每个类的平均百分比参与百分比和参与百分比

我已经尝试了聚合函数和带有+点的ggplot函数,没有运气

1 个答案:

答案 0 :(得分:0)

library(ggplot2)
library(dplyr)


df1 <- df %>% group_by(Class) %>% summarise_all(funs(mean))

ggplot(df1, aes(x = Percent_Attended, y = Percent_Participated)) + 
        geom_point(aes(color = factor(Class)), size = 3)

enter image description here

数据

structure(list(Class = c(3L, 3L, 2L, 7L), Percent_Attended = c(0.8, 
0.5, 0.9, 0.92), Percent_Participated = c(0.6, 0.4, 0.5, 0.8)), .Names = c("Class", 
"Percent_Attended", "Percent_Participated"), class = "data.frame", row.names = c(NA, 
-4L))