[R] help with a special variant of balloonplot

ravi rv15i at yahoo.se
Mon Aug 27 00:00:25 CEST 2012


Hi Peter and r-list members,
Thanks a lot for your help. Your solution with the myballoonplot has solved two issues : the original numbers are retained in the table and the colour locations are right. But I have one more requirement - that the sizes should be proportional to the magnitude of the new variable, Freqdev. As it stands, the balloonsizes are the same as before i.e. proportional to the magnitude of Freq.
It appears to me that the myballoonplot function must take in an additional argument, the variable that decides the balloon size. I will try to dig into the code to see how this new parameter can be accomodated into the code. I must confess that I am far from a pro at this sort of stuff. I will appreciate it if I can get some help. However, I will also give it a try myself. Will come back later if I run into problems.
Thanks,
Ravi


----- Original Message -----
From: Peter Ehlers <ehlers at ucalgary.ca>
To: ravi <rv15i at yahoo.se>
Cc: "r-help at r-project.org" <r-help at r-project.org>
Sent: Sunday, 26 August 2012, 1:13
Subject: Re: [R] help with a special variant of balloonplot

On 2012-08-24 09:12, ravi wrote:
> Hi,
> I am interested in implementing a special variant of
> balloonplot.  Let me
> explain with an example dataset from the reference manual :
>
> library(gplots)
> data(Titanic)
> dframe<-as.data.frame(Titanic)
> survived<-dframe[dframe$Survived=="Yes",]
> attach(survived)
> balloonplot(x=Class,y=list(Age,Sex),z=Freq,sort=TRUE,show.zeros=TRUE,cum.margins=FALSE,
>              main="BalloonPlot : Surviving passengers") # standard plot
> # Now comes the attempt at something more special
> FreqThresh=50 # A threshold level
> Freqdev<-Freq-FreqThresh # A new variable
> colors=ifelse(Freqdev>0,"green","magenta")
> balloonplot(x=Class,y=list(Age,Sex),z=Freqdev,sort=TRUE,show.zeros=TRUE,cum.margins=FALSE,dotcol=colors,
> show.margins=FALSE,main="BalloonPlot : Surviving passengers")
>
> I am interested in a table with the
> values unchanged from the titanic dataframe. These values should be highlighted
> in balloons in two different colours, let’s say, green and magenta. For
> positive values of Freqdev, the balloons will be green and have a size
> depending on the magnitude of Freqdev. For negative values of Freqdev, the balloons
> will have a colour of magenta and have a size proportional to the absolute
> values of Freqdev.
> I am not sure if a simple tweak can lead to a solution.

I see that you have by now received help on how to access the
source code for balloonplot.default. Here's the change you
probably have in mind for the above:

In balloonplot.default(), find the following two lines (they're
in a function myscale() defined within balloonplot):

         X[X<0] <- 0
         X <- sqrt(X)

Comment out these lines and replace them with

         X <- sqrt(abs(X))

Save the resulting function as myballoonplot and use that in
your code.

While you're at it, you might remove the attach(survived)
statement and use

   with(survived, myballoonplot(....))

Peter Ehlers

>
> I will appreciate any help that I can get.
> Thanks,
> Ravi
>
>     [[alternative HTML version deleted]]
>




More information about the R-help mailing list