[R] Bubble plots

Franz Mueter fmueter at alaska.net
Sun Aug 3 18:30:47 CEST 2008


I believe 
?symbols
is what you are looking for. Of course, you need to convert categories to
numeric values for plotting:

For example, adding some actual data to your data frame:

> D <- cbind(D, P = runif(15))
> symbols(as.numeric(D$time), as.numeric(D$y), circles=D$P, inches=0.2,
ann=F, xaxt="n", yaxt="n")

Use axis() to get proper axis labels:
> axis(1, 1:3, levels(D$time))
> axis(2, 1:4, levels(D$y))


Franz

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of Cody Hamilton
Sent: Friday, August 01, 2008 7:07 PM
To: r-help at r-project.org
Subject: [R] Bubble plots

Is there a way to create a 'bubble plot' in R?

For example, if we define the following data frame containing the level of y
observed for 5 patients at three time points:

time<-c(rep('time 1',5),rep('time 2',5),rep('time 3',5))
y<-c('a','b','c','d','a','b','c','a','d','a','a','a','b','c','d')
D<-data.frame(cbind(y,time))

I would like to display the percentage of subjects in each level of y at
each time point as a bubble whose size is proportional to the percentage of
subjects in the given level of y at the given time point.  Thus, in the case
of the data frame above the plot would have the levels of y
('a','b','c','d') on the y-axis and the levels of time ('time 1','time 2',
time 3') on the x-axis with four bubbles above each time point (e.g. the
size of the bubble in the bottom left corner of the plot would be
proportional to the percentage of patients with y='a' at time='time 1').

I am running R 2.7.1 under windows.

Regards,
   -Cody



________________________________
This message contains information which may be confident...{{dropped:8}}



More information about the R-help mailing list