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. I do hope someone can help me. -- Regards/Groete/Mit freundlichen Gr??en/recuerdos/meilleures salutations/ distinti saluti/siong/du? y?/?????? Jurgens de Bruin -------------- next part -------------- A non-text attachment was scrubbed... Name: bubble.png Type: image/png Size: 290394 bytes Desc: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110414/b7ca9585/attachment.png>
Jurgens de Bruin <debruinjj <at> gmail.com> writes:> > 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. >A reproducible example would be great. something along the lines of library(ggplot2) ggplot(mydata,aes(x=drugclass,y=plant,colour=fitvalue,size=?))+geom_point() it's not clear from your description what determines the size. From a labeling point of view, switching x and y might be useful.
I think using base graphics you would need to use numerical vectors to set the bubble positions. However there is not reason that you could not suppress the axis labeling and apply your own. This code does the first part using circles. There are probably better ways to do it but this should work. See ?par xaxt and yaxt to suppress the labeling and have look at axis for how to add the category labels --- On Thu, 4/14/11, Jurgens de Bruin <debruinjj at gmail.com> wrote:> From: Jurgens de Bruin <debruinjj at gmail.com> > Subject: [R] Categorical bubble plot > To: r-help at r-project.org > Received: Thursday, April 14, 2011, 9:48 AM > 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. > > I do hope someone can help me. > > > -- > Regards/Groete/Mit freundlichen > Gr??en/recuerdos/meilleures salutations/ > distinti saluti/siong/du? y?/?????? > > Jurgens de Bruin > > -----Inline Attachment Follows----- > > ______________________________________________ > R-help at 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. >
Jurgens de Bruin <debruinjj <at> gmail.com> writes:> > 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. > > I do hope someone can help me. >Have a look at function balloonplot in package gplots. http://finzi.psych.upenn.edu/R/library/gplots/html/balloonplot.html It may do what you want or at least give you some hints. Michael bibo Queensland Health
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