On 04/14/2011 11:48 PM, Jurgens de Bruin wrote:
Hi,
I do not have much R experience just the basics, so please excuse
any obvious questions.
I would like to create bubble plot that have Categorical data on the x and y
axis and then the diameter if the bubble the value related to x and y.
Attached to the email is a pic of what I would like to do.
Hi Jurgens,
Below is a little demo of what you can do. Your example has more in it
than you have described, so if you want the third dimension (Fit) you
will have to expand this to multiple circles at one point. I will
probably redo this plot and add it to the plotrix package sometime.
bubbleGumPlot<-function(xdiam,xcol,xlabels,ylabels,redrange=c(0,1),
greenrange=c(0,1),bluerange=c(0,1),extremes=NA,na.color=NA,
main="",xlab="",ylab="",staxx=FALSE,staxy=FALSE,srt=NA,...) {
bubblecol<-color.scale(xcol,redrange=redrange,greenrange=greenrange,
bluerange=bluerange,extremes=extremes,na.color=NA)
bubblediam<-rescale(xdiam,c(0.05,0.5))
dimx<-dim(xcol)
plot(NA,xlim=c(0.5,dimx[2]+0.5),ylim=c(0.5,dimx[1]+0.5),type="n",
main=main,xlab=xlab,ylab=ylab,axes=FALSE,...)
if(staxx) staxlab(1,at=1:dimx[2],labels=colnames(xcol),srt=srt)
else axis(1,at=1:dimx[2],labels=colnames(xcol))
if(staxy) staxlab(2,at=1:dimx[1],labels=rownames(xcol))
else axis(2,at=1:dimx[1],labels=rownames(xcol))
box()
for(row in dimx[1]:1) {
for(column in 1:dimx[2])
draw.circle(column,row,radius=bubblediam[dimx[1]-row+1,column],
col=bubblecol[dimx[1]-row+1,column])
}
}
colmat<-matrix(runif(48),nrow=6,ncol=8)
diammat<-matrix(runif(48),nrow=6,ncol=8)
rownames(colmat)<-c("Apple","Blackberry","Blueberry","Cherry","Peach","Pear")
colnames(colmat)<-c("Sweet","Sour","Salty","Bitter","Pleasant","Bland","Smooth",
"Pungent")
bubbleGumPlot(diammat,colmat,staxx=TRUE,staxy=TRUE,
main="Test of bubbleGumPlot",xlab="Characteristics",ylab="Fruits")
Jim
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.