使用ggplot2创建气球图:使用..count ..来调整geom_point的大小? [英] Create balloon plot with ggplot2: use ..count.. to adjust size of geom_point?

查看:251
本文介绍了使用ggplot2创建气球图:使用..count ..来调整geom_point的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我基本上想用 ggplot2 创建一个气球图,其中点的大小是指定坐标处数据的频率。



给定data.frame d

  d =结构(列表(value.x =结构(c(2L,2L,3L,2L,3L,2L,2L,2L,3L,2L,2L,1L,2L,1L,2L,1L,1L,1L) ,2L,2L),.Label = c(根本不知道,有点知识渊博,非常知识渊博),class = c(ordered,factor)),value.y = structure(c (5L,5L,3L,5L,5L,5L,5L,5L,4L,4L,5L,4L,4L,4L,5L,4L,5L,5L,4L,4L),标签= c知识丰富,知识少,与以前相同,更有见识,知识更丰富),class = c(ordered,factor))),.Names = c(value。 x,value.y),row.names = c(NA,20L),class =data.frame)

我想要这样做:

  ggplot(d,aes(value.x,value .y,size = .. count ..))+ geom_point()

其中数据点与数据发生次数成正比,但我无法弄清楚如何正确设置我想要的点的大小。



重要的是,我想避免在 d 中创建一个新列,只是为了与其他数据集(例如, http://www.r-bloggers.com/balloon-plot-using- GGPLOT2 / )。这似乎很麻烦,我想利用 ggplot2 的力量。如果可以的话。

我发现一个解决方案使用 stat_sum()

  ggplot(d,aes(value.x,value.y,size = ..n ..))+ stat_sum()


I want to essentially create a balloon plot with ggplot2 where the size of the points are the frequency of data at a given coordinate.

Given the data.frame d:

d = structure(list(value.x = structure(c(2L, 2L, 3L, 2L, 3L, 2L, 2L, 2L, 3L, 2L, 2L, 1L, 2L, 1L, 2L, 1L, 1L, 1L, 2L, 2L), .Label = c("Not at all Knowledgeable", "Somewhat Knowledgeable", "Very Knowledgeable"), class = c("ordered", "factor")), value.y = structure(c(5L, 5L, 3L, 5L, 5L, 5L, 5L, 5L, 4L, 4L, 5L, 4L, 4L, 4L, 5L, 4L, 5L, 5L, 4L, 4L), .Label = c("Much less knowledgeable", "Less knowledgeable", "Same as before workshop", "More knowledgeable", "Much more knowledgeable"), class = c("ordered", "factor"))), .Names = c("value.x", "value.y"), row.names = c(NA, 20L), class = "data.frame")

I want to do something like:

ggplot(d,aes(value.x,value.y,size=..count..))+geom_point()

where the data points are proportional to how many times data occur, but I cannot figure out how to properly set the size of the points for what I want.

Importantly, I would like to avoid creating a new column in d just for counts of data as has been done with other datasets (e.g. http://www.r-bloggers.com/balloon-plot-using-ggplot2/). This seems messy and I would like to utilize ggplot2's power if I can.

解决方案

Per @BenBolker's suggestion, I found a solution using stat_sum():

ggplot(d, aes(value.x, value.y, size = ..n..)) + stat_sum()

这篇关于使用ggplot2创建气球图:使用..count ..来调整geom_point的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆