Try this: library(gplots) m <- matrix(c(1, 2, -3, -6, 5, 4), 3) tm <- t(m) balloonplot(row(tm), col(tm), abs(tm), dotcolor = c("blue", "red")[(c(tm) > 0) + 1], show.margins = FALSE, cum.margins = FALSE, xlab = "Cols", ylab = "Rows", main = "m")
On Wed, Apr 14, 2010 at 7:58 AM, Guy Green <guygr...@netvigator.com> wrote: > > Hello, > > I am trying to create a graphic to help me visualise data. A (very > simplified) sample of the data is > http://n4.nabble.com/file/n1839676/circle_data.txt circle_data.txt : > > Aug-07 Nov-07 Feb-08 > data1 1 1.5 -1 > data2 1 1.2 1.6 > data3 1.3 1.4 1.8 > data4 1.3 -1.2 1 > > What I am trying to achieve is: > > * Circles representing each item of data, > * The circle size represents the number, > * The data is arranged in rows and columns, similar to the table layout > (i.e. dates along the top or bottom), > * Positive numbers are blue circles, negative red circles. > > I have used info from lots of previous posts on symbols() to get me some of > the way, but I am still far off getting it to actually work, with the result > that I think I may be heading in completely the wrong direction. I can > create a grid of circles with the right number of dimensions: > > Read_data=read.table("C:/files/circle_data.txt", head = T) > number_rows = nrow(Read_data) > number_cols = ncol(Read_data) > xaxis = rep(seq(1,ncol(Read_data),1),nrow(Read_data)) > yaxis = rep(seq(1,nrow(Read_data),1),ncol(Read_data)) > zvalues = rep(0.1,(number_rows*number_cols)) #This is just a dummy vector > symbols(xaxis, yaxis, circles = zvalues, inches = FALSE, xlab="", ylab="") > axis(2, at=c(1:number_rows), rownames(Read_data), las = 1) > axis(1, at=c(1:number_cols), colnames(Read_data)) > > BUT... this only uses dummy values - I can't think how to get the table into > a form the symbols() function can use. I tried as.vector() unsuccessfully. > Also, this code simply overwrites the x and y-axis labels, which looks > terrible: again, I can't think how to get this right from the start. > > On getting positive values to be blue and negative red, I had assumed I > could just split the data into two and plot separately: > > Data_positive = replace(Read_data, Read_data<0,0) > Data_negative = -replace(Read_data, Read_data>0,0) > > However, this quick trial below gives little dots for zero values, so it is > not a perfect result: > > zvalues_pos = rep(c(0.1,0.2,0), 4) #Dummy vector for positives > zvalues_neg = rep(c(0,0,0.3), 4) #Dummy vector for negatives > symbols(xaxis, yaxis, circles = zvalues_pos, inches = FALSE, xlab="", > ylab="", bg="blue") > symbols(xaxis, yaxis, circles = zvalues_neg, inches = FALSE, xlab="", > ylab="", bg="red", add=TRUE) > > [Incidentally, I have tried to work through this example ( > http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=152 > http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=152 ) but I am > out of my depth in making sense of the code.] > > Any help would be gratefully received. Thanks, > > Guy > -- > View this message in context: > http://n4.nabble.com/Problems-getting-symbols-to-show-table-data-tp1839676p1839676.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@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. > ______________________________________________ R-help@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.