Hi Guys, I have been trying to create a 'balloon plot' using R, which is where the points in a plot are scaled such that the size of the point (area) represents the value. Eg. A small point may represent 2 and a big point may represent 10. The problem is that my data range between 0.3 and 0.52, which is a very small difference between the smallest and largest values. I would like 0.3 to be represented by the smallest balloon (point) and 0.52 to be represented by the largest balloon (point). The code allows you to enter 'limits' which I set from 0.3 to 0.52 but regardless of this it seems to scale the balloons assuming that the scale starts at 0, rather than at 0.3. As a result, the difference in size between my different values is barely noticeable- all the balloons are close to the largest size. The matrix of data is too large for me to add here, but imagine a square matrix with headers along the top and sizes like this: X a_PMd b_SMAproper c_pre.SMA d_M1a e_S1 f_CMA g_PMv h_M1p 1 a_PMd 0.4938019 0.5076123 0.5135090 0.4906899 0.4021556 0.4212536 0.4038168 0.3471316 2 b_SMAproper 0.5076123 0.4814135 0.4728626 0.4372118 0.3008708 0.4024063 0.4249524 0.4133340 3 c_pre-SMA 0.5135090 0.4728626 0.4727388 0.3944285 0.4695559 0.3870128 0.4082124 NA 4 d_M1a 0.4906899 0.4372118 0.3944285 0.4675951 0.4450485 0.3899106 0.3376981 0.4298238 5 e_S1 0.4021556 0.3008708 0.4695559 0.4450485 0.4158451 0.3941677 0.3055601 0.3726385 6 f_CMA 0.4212536 0.4024063 0.3870128 0.3899106 0.3941677 0.3656597 0.3655603 0.4112778 7 g_PMv 0.4038168 0.4249524 0.4082124 0.3376981 0.3055601 0.3655603 0.3471682 0.3035210 8 h_M1p 0.3471316 0.4133340 NA 0.4298238 0.3726385 0.4112778 0.3035210 0.3267115 I then use Melt to put it into the format that the plot requires: krdata2<-melt(krdata1,value.name="median") balloon=ggplot(krdata2,aes(x=X,y=variable))+ geom_point(aes(size=median),shape=21,color="black",fill="lightblue")+ scale_size_area(max_size=40,limits=c(0.3, 0.52),guide="legend", breaks=waiver(), expand=waiver()) print(balloon) As you can see, I have set the limited to 0.3- 0.52, but still it assumes that the scale starts at 0 and the smallest balloon would be around a value of 0.1. Anybody got any ideas for how to change this scaling?? I would be very grateful!! Thank you in advance Kathy
On Fri, 23 May 2014 12:19:11 PM Ruddy Kathy wrote:> Hi Guys, > > I have been trying to create a 'balloon plot' using R, which is where the > points in a plot are scaled such that the size of the point (area) > represents the value. > ... > Anybody got any ideas for how to change this scaling?? > I would be very grateful!! >Hi Kathy, This isn't ggplot, but you can apply whatever scaling function you want in size_n_color (plotrix). I read in your example as a data frame named "krdata2". Perhaps it will be useful. krmed<-sapply(krdata2[,2:9],median,na.rm=TRUE) x11(width=8,height=3) stretch_it<-function(x) (x+0.65)^5 library(plotrix) size_n_color(seq(1,32,length.out=8),rep(1,8),krmed, sizefun="stretch_it", xlim=c(0,32),col=rep(3,8), xat=seq(1,32,length.out=8),yat=c(0.5,1.5), main="size_n_color",xlab="",ylab="", xaxlab=names(krmed),mar=c(5,4,4,5)) Jim