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-----
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.
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
Thanks for the reply...
with reproducible I am believe you require a dataset?
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))
The size of the bubbles will be related to the fitvalues.
On 14 April 2011 17:57, Ben Bolker <bbolker at gmail.com
<mailto:bbolker at gmail.com>> wrote:
Jurgens de Bruin <debruinjj <at> gmail.com <http://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.
______________________________________________
R-help at r-project.org <mailto: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.
--
Regards/Groete/Mit freundlichen Gr??en/recuerdos/meilleures salutations/
distinti saluti/siong/du? y?/??????
Jurgens de Bruin