R软件如何绘制气泡图?
1、这里以R数据集trees为例。该数据集有三个变量Girth、Height、Volume。
我们以Height、Volume为x、y变量,对Girth变量进行处理,作为气泡半径大小。
attach(mtcars)
r=Girth/(2*pi) # 根据圆周长公式计算半径

2、设置各参数值,绘制图像。
N<-nrow(trees)#数据集的行数,即观察值的个数
symbols(Height,Volume,circles=r,inches=0.25,fg="grey",bg=rainbow(N),main="The symbols of trees ,circles=Girth/(2*pi)",xlab="Height",ylab="Volume")
text(Height,Volume,1:N) #为每个气泡添加标签
detach(trees)

3、绘制方格图,可以将circles=r替换成squares=r。
symbols(Height,Volume,squares=r,inches=0.25,fg="grey",bg=rainbow(N),main="The symbols of trees ,squares=Girth/(2*pi)",xlab="Height",ylab="Volume")
text(Height,Volume,1:N) #为每个气泡添加标签

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
阅读量:187
阅读量:44
阅读量:58
阅读量:164
阅读量:116