分类气泡图用于制图研究 [英] Categorical bubble plot for mapping studies

查看:227
本文介绍了分类气泡图用于制图研究的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用GNU R创建分类气泡图,类似于系统制图研究中使用的泡沫图(见下文)?

How to create a categorical bubble plot, using GNU R, similar to that used in systematic mapping studies (see below)?

好的,这是到目前为止我尝试过的.首先,我的数据集(Var1进入x轴,Var2进入y轴):

ok, here's what I've tried so far. First, my dataset (Var1 goes to the x-axis, Var2 goes to the y-axis):

> grid
                         Var1                      Var2 count
1              Does.Not.apply            Does.Not.apply    53
2               Not.specified            Does.Not.apply    15
3   Active.Learning..general.            Does.Not.apply     1
4      Problem.based.Learning            Does.Not.apply     2
5              Project.Method            Does.Not.apply     4
6         Case.based.Learning            Does.Not.apply    22
7               Peer.Learning            Does.Not.apply     6
10                      Other            Does.Not.apply     1
11             Does.Not.apply             Not.specified    15
12              Not.specified             Not.specified    15
21             Does.Not.apply Active.Learning..general.     1
23  Active.Learning..general. Active.Learning..general.     1
31             Does.Not.apply    Problem.based.Learning     2
34     Problem.based.Learning    Problem.based.Learning     2
41             Does.Not.apply            Project.Method     4
45             Project.Method            Project.Method     4
51             Does.Not.apply       Case.based.Learning    22
56        Case.based.Learning       Case.based.Learning    22
61             Does.Not.apply             Peer.Learning     6
67              Peer.Learning             Peer.Learning     6
91             Does.Not.apply                     Other     1
100                     Other                     Other     1

然后,尝试绘制数据:

# Based on http://flowingdata.com/2010/11/23/how-to-make-bubble-charts/
grid <- subset(grid, count > 0)
radius <- sqrt( grid$count / pi )
symbols(grid$Var1, grid$Var2, radius, inches=0.30, xlab="Research type", ylab="Research area")
text(grid$Var1, grid$Var2, grid$count, cex=0.5)

结果如下:

问题:轴标签错误,虚线虚线丢失.

Problems: axis labels are wrong, the dashed grid lines are missing.

推荐答案

这是ggplot2解决方案.首先,将半径作为新变量添加到数据框中.

Here is ggplot2 solution. First, added radius as new variable to your data frame.

grid$radius <- sqrt( grid$count / pi )

您应该在绘图中试一下点和文本标签的大小,以使其完美契合.

You should play around with size of the points and text labels inside the plot to perfect fit.

library(ggplot2)
ggplot(grid,aes(Var1,Var2))+
  geom_point(aes(size=radius*7.5),shape=21,fill="white")+
  geom_text(aes(label=count),size=4)+
  scale_size_identity()+
  theme(panel.grid.major=element_line(linetype=2,color="black"),
        axis.text.x=element_text(angle=90,hjust=1,vjust=0))

这篇关于分类气泡图用于制图研究的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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