Skip to content

Categorical bubble plot

9 messages · Jurgens de Bruin, John Kane, Michael Bibo +3 more

#
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.
#
Jurgens de Bruin <debruinjj <at> gmail.com> writes:
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:

            
#
Jurgens de Bruin <debruinjj <at> gmail.com> writes:
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 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
#
On 04/15/2011 01:13 AM, Jurgens de Bruin wrote:
yes -- but you can make one up if you like.  e.g.


dd <- expand.grid(drugclass=LETTERS[1:5],
   plant=c("cactus","sequoia","mistletoe"))
set.seed(101)
dd$fitvalue <- runif(nrow(dd))

library(ggplot2)
ggplot(dd,aes(x=drugclass,y=plant,colour=fitvalue,size=fitvalue))+
  geom_point()

  By the way, I think you could represent your data much more
clearly this way: the "Cleveland hierarchy" says that it's easier
to assess quantitative values plotted along a common scale than via
size or colour ...

ggplot(dd,aes(x=drugclass,y=fitvalue,colour=plant))+
  geom_point()+geom_line(aes(group=plant))
5 days later