Dear Group, I have the following data matrix which is a timeseries.> dput(tData)structure(list(A = c(0.2, 0.13, 0.05, 0.1, 0.02, 0.18, 0.09, 0.06, 0.13), B = c(0.15, 0.06, 0.09, 0.02, 0.03, 0.12, 0.01, 0.15, 0.06), C = c(-0.1, 0, -0.07, -0.06, -0.05, -0.05, -0.06, -0.08, -0.07), D = c(-0.15, -0.05, -0.1, -0.03, -0.13, -0.04, -0.1, -0.04, -0.15), E = c(-0.17, -0.16, -0.08, -0.07, -0.09, -0.14, -0.1, -0.05, 0)), .Names = c("A", "B", "C", "D", "E"), class "data.frame", row.names = c(NA, -9L)) I am trying to display this data in a graphic. The values vary from -0.2 to +0.2 There should be a table with 5 Rows and 9 Columns. Rows labeled A to E and Columns labeled 1 to 9. Inside each cell there should be a circle (sphere preferable) with radius of mod(data value). The color should be either red or green depending on -ve or +ve and the intensity should be based on the value of the datapoint. Any help on how to go about this? Thanks, S
On Tue, Nov 2, 2010 at 10:07 PM, Santosh Srinivas <santosh.srinivas at gmail.com> wrote:> Dear Group, > I have the following data matrix which is a timeseries. > >> dput(tData) > structure(list(A = c(0.2, 0.13, 0.05, 0.1, 0.02, 0.18, 0.09, > 0.06, 0.13), B = c(0.15, 0.06, 0.09, 0.02, 0.03, 0.12, 0.01, > 0.15, 0.06), C = c(-0.1, 0, -0.07, -0.06, -0.05, -0.05, -0.06, > -0.08, -0.07), D = c(-0.15, -0.05, -0.1, -0.03, -0.13, -0.04, > -0.1, -0.04, -0.15), E = c(-0.17, -0.16, -0.08, -0.07, -0.09, > -0.14, -0.1, -0.05, 0)), .Names = c("A", "B", "C", "D", "E"), class > "data.frame", row.names = c(NA, > -9L)) > > > I am trying to display this data in a graphic. The values vary from -0.2 to > +0.2 > There should be a table with 5 Rows and 9 Columns. Rows labeled A to E and > Columns labeled 1 to 9. > Inside each cell there should be a circle (sphere preferable) with radius of > mod(data value). The color should be either red or green depending on -ve or > +ve and the intensity should be based on the value of the datapoint. >See balloonplot in the gplots package. -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com
Thanks Gabor. I used melt to transform the data and plot using balloonplot. tData <- structure(list(A = c(0.2, 0.13, 0.05, 0.1, 0.02, 0.18, 0.09, 0.06, 0.13), B = c(0.15, 0.06, 0.09, 0.02, 0.03, 0.12, 0.01, 0.15, 0.06), C = c(-0.1, 0, -0.07, -0.06, -0.05, -0.05, -0.06, -0.08, -0.07), D = c(-0.15, -0.05, -0.1, -0.03, -0.13, -0.04, -0.1, -0.04, -0.15), E = c(-0.17, -0.16, -0.08, -0.07, -0.09, -0.14, -0.1, -0.05, 0)), .Names = c("A", "B", "C", "D", "E"), class = "data.frame", row.names = c(NA, -9L)) tData$Period <- rownames(tData) tData.m <- melt(tData) # need to find a way to adjust the color for -ve values balloonplot(tData.m$Period,tData.m$variable,abs(tData.m$value)) -----Original Message----- From: Gabor Grothendieck [mailto:ggrothendieck at gmail.com] Sent: 03 November 2010 07:51 To: Santosh Srinivas Cc: r-help at r-project.org Subject: Re: [R] Drawing circles on a chart On Tue, Nov 2, 2010 at 10:07 PM, Santosh Srinivas <santosh.srinivas at gmail.com> wrote:> Dear Group, > I have the following data matrix which is a timeseries. > >> dput(tData) > structure(list(A = c(0.2, 0.13, 0.05, 0.1, 0.02, 0.18, 0.09, > 0.06, 0.13), B = c(0.15, 0.06, 0.09, 0.02, 0.03, 0.12, 0.01, > 0.15, 0.06), C = c(-0.1, 0, -0.07, -0.06, -0.05, -0.05, -0.06, > -0.08, -0.07), D = c(-0.15, -0.05, -0.1, -0.03, -0.13, -0.04, > -0.1, -0.04, -0.15), E = c(-0.17, -0.16, -0.08, -0.07, -0.09, > -0.14, -0.1, -0.05, 0)), .Names = c("A", "B", "C", "D", "E"), class > "data.frame", row.names = c(NA, > -9L)) > > > I am trying to display this data in a graphic. The values vary from -0.2to> +0.2 > There should be a table with 5 Rows and 9 Columns. Rows labeled A to E and > Columns labeled 1 to 9. > Inside each cell there should be a circle (sphere preferable) with radiusof> mod(data value). The color should be either red or green depending on -veor> +ve and the intensity should be based on the value of the datapoint. >See balloonplot in the gplots package. -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com
On Tue, Nov 2, 2010 at 10:58 PM, Santosh Srinivas <santosh.srinivas at gmail.com> wrote:> Thanks Gabor. I used melt to transform the data and plot using balloonplot. > > tData <- structure(list(A = c(0.2, 0.13, 0.05, 0.1, 0.02, 0.18, 0.09, 0.06, > ?0.13), B = c(0.15, 0.06, 0.09, 0.02, 0.03, 0.12, 0.01, 0.15, 0.06), C > ?= c(-0.1, 0, -0.07, -0.06, -0.05, -0.05, -0.06, -0.08, -0.07), D > ?c(-0.15, -0.05, -0.1, -0.03, -0.13, -0.04, -0.1, -0.04, -0.15), E > ?c(-0.17, -0.16, -0.08, -0.07, -0.09, -0.14, -0.1, -0.05, 0)), .Names > ?c("A", "B", "C", "D", "E"), class = "data.frame", row.names = c(NA, > ?-9L)) > > tData$Period <- rownames(tData) > > tData.m <- melt(tData) > > # need to find a way to adjust the color for -ve values > balloonplot(tData.m$Period,tData.m$variable,abs(tData.m$value)) >You can also try fixing up this where TS is dput object: mat <- as.matrix(TS) plot(col(TS) ~ row(TS), cex = 5 * (mat - min(mat)) / diff(range(mat)), col = 1 + (mat > 0)) -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com
On Wed, Nov 3, 2010 at 2:07 AM, Santosh Srinivas <santosh.srinivas at gmail.com> wrote:> Dear Group,> Inside each cell there should be a circle (sphere preferable) with radius of > mod(data value). The color should be either red or green depending on -ve or > +ve and the intensity should be based on the value of the datapoint. > > Any help on how to go about this?If you really want a sphere then you should look at the rgl package, which enables the drawing of 3d graphic objects with illumination. However it does it in its own graphics window and you'll not be able to use any of the standard R graphics functions. Otherwise you'll have to find some way of putting a 3d sphere on a 2d R graphics window, or faking it with a shaded circle and some highlights. Yuck. Also, drawing circles (strictly, a disc) with radius proportional to data value is usually a bad idea since we interpret areas. A circle with twice the radius has four times the area, and so looks four times as big. But the data is only twice as big... Barry