Is there anyway to plot a matrix using a 3d bar plot. Something like bar3 in matlab? The example in demo hist3d does a 3d barplot for binned data, but has anyone tried something for a simple matrix with spaces betwen bars and axis labels using matrix dimnames or 1,2,3? stages<-letters[1:3] A<-matrix(c( 0.21, 0.21,0.03, 0.55, 0.58, 0.09, 1.30, 1.35, 0.22), nrow=3, byrow=TRUE, dimnames=list(stages,stages) ) ## I can get a surface plot, but that's about it. persp3d(A, col="red", alpha=0.7, xlab="fate", ylab="stage", zlab="Sensitivity", box=FALSE) Thanks, Chris Stubben -- ------------------- Los Alamos National Lab BioScience Division MS M888 Los Alamos, NM 87545
3d barplot in rgl
9 messages · Chris Stubben, Hadley Wickham, Duncan Murdoch +1 more
Why do you want a 3d barchart? They are generally a bad way to present information as tall bars can obscure short bars, and it is hard to accurately read off the height of a bar. While adding rotation can reduce some of these problems, why not create a graphic that your viewers can take in with a glance? Hadley
On 9/25/07, stubben <stubben at lanl.gov> wrote:
Is there anyway to plot a matrix using a 3d bar plot. Something like bar3 in matlab? The example in demo hist3d does a 3d barplot for binned data, but has anyone tried something for a simple matrix with spaces betwen bars and axis labels using matrix dimnames or 1,2,3? stages<-letters[1:3] A<-matrix(c( 0.21, 0.21,0.03, 0.55, 0.58, 0.09, 1.30, 1.35, 0.22), nrow=3, byrow=TRUE, dimnames=list(stages,stages) ) ## I can get a surface plot, but that's about it. persp3d(A, col="red", alpha=0.7, xlab="fate", ylab="stage", zlab="Sensitivity", box=FALSE) Thanks, Chris Stubben -- ------------------- Los Alamos National Lab BioScience Division MS M888 Los Alamos, NM 87545
______________________________________________ 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.
On 9/25/2007 2:34 PM, stubben wrote:
Is there anyway to plot a matrix using a 3d bar plot. Something like bar3 in matlab? The example in demo hist3d does a 3d barplot for binned data, but has anyone tried something for a simple matrix with spaces betwen bars and axis labels using matrix dimnames or 1,2,3?
That demo gives you the basics of the code, so it shouldn't be too hard to put your own together: just strip out the counting part. Duncan Murdoch
hadley wickham <h.wickham <at> gmail.com> writes:
Why do you want a 3d barchart? They are generally a bad way to present information as tall bars can obscure short bars, and it is hard to accurately read off the height of a bar. While adding rotation can reduce some of these problems, why not create a graphic that your viewers can take in with a glance?
3d barplots are a common way to display sensitvity/elasticity matrices in stage-structured demography. Here's a few other options from Caswell's Matrix population models book (2001) - I definitely prefer 3d barcharts to these alternatives. heatmap(log10(A[3:1,]), Rowv = NA, Colv = NA, scale="none") plot(log10(c(A)), type="s") Thanks, Chris
Duncan Murdoch <murdoch <at> stats.uwo.ca> writes:
That demo gives you the basics of the code, so it shouldn't be too hard to put your own together: just strip out the counting part.
Thanks, I did download the source to check the hist3d demo, but honestly it didn't look very easy to simplify. I switched to R from matlab, and 3d barplots are the only thing I still use my student edition of matlab for anymore. I would like to see a barplot3d added to your rgl package in the future, but was hoping someone else had tried already. Chris
On 9/25/07, Chris Stubben <stubben at lanl.gov> wrote:
hadley wickham <h.wickham <at> gmail.com> writes:
Why do you want a 3d barchart? They are generally a bad way to present information as tall bars can obscure short bars, and it is hard to accurately read off the height of a bar. While adding rotation can reduce some of these problems, why not create a graphic that your viewers can take in with a glance?
3d barplots are a common way to display sensitvity/elasticity matrices in stage-structured demography. Here's a few other options from Caswell's Matrix population models book (2001) - I definitely prefer 3d barcharts to these alternatives. heatmap(log10(A[3:1,]), Rowv = NA, Colv = NA, scale="none") plot(log10(c(A)), type="s")
Both of those look like equally awful alternatives. Perhaps you could explain more about your data (perhaps with a sample?) so that we could suggest better alternatives. Hadley
On 9/25/2007 3:13 PM, Chris Stubben wrote:
Duncan Murdoch <murdoch <at> stats.uwo.ca> writes:
That demo gives you the basics of the code, so it shouldn't be too hard to put your own together: just strip out the counting part.
Thanks, I did download the source to check the hist3d demo, but honestly it didn't look very easy to simplify. I switched to R from matlab, and 3d barplots are the only thing I still use my student edition of matlab for anymore. I would like to see a barplot3d added to your rgl package in the future, but was hoping someone else had tried already.
They probably will someday, but not until someone who needs them sits down and writes the code. I tend to agree with Hadley that they aren't a particularly effective sort of graph so it'll likely be someone else. Duncan Murdoch
hadley wrote:
On 9/25/07, Chris Stubben <stubben at lanl.gov> wrote:
hadley wickham <h.wickham <at> gmail.com> writes:
Why do you want a 3d barchart? They are generally a bad way to present information as tall bars can obscure short bars, and it is hard to accurately read off the height of a bar. While adding rotation can reduce some of these problems, why not create a graphic that your viewers can take in with a glance?
3d barplots are a common way to display sensitvity/elasticity matrices in stage-structured demography. Here's a few other options from Caswell's Matrix population models book (2001) - I definitely prefer 3d barcharts to these alternatives. heatmap(log10(A[3:1,]), Rowv = NA, Colv = NA, scale="none") plot(log10(c(A)), type="s")
Both of those look like equally awful alternatives. Perhaps you could explain more about your data (perhaps with a sample?) so that we could suggest better alternatives. Hadley
Transition matrices are Markov transition matrices among different
life stages of organisms -- in the simplest case (Leslie matrices,
tracking age-structured populations), the top row of the matrix represents
fecundity and the first off-diagonal (below the diagonal) represents
survival. The elasticities and sensitivities are differential (absolute
or proportional) responses
of long-run population growth rate [i.e., the largest eigenvalue] to changes
in
matrix elements.
In the Leslie case the matrix is quite sparse and it would be easy to just
plot sensitivities/elasticities of fecundities and survivorship.
In the more complicated case (Lefkovitch matrices), the categories
represent
stages rather than ages so individuals can stay in the same class from year
to year,
or even revert to the previous class, so the matrix is less sparse and the
problem
is a little more challenging.
Here are some data from the popbio package on CRAN
for playing with.
library(popbio)
example(teasel) ## shows 2 plots -- heatmap and stair-step
A <- tea$sensitivities ##
Here's one possibility, setting 0 sensitivities to NA to omit
them from the plot:
z <- as.data.frame.table(A)
names(z) <- c("From","To","Sensitivity")
z$Sensitivity[z$Sensitivity==0] <- NA
dotplot(From~Sensitivity|To,data=z)
dotplot(From~Sensitivity|To,data=z,scales=list(x=list(log=TRUE)))
I turned the plot horizontally to make it easier to draw labels
(as lattice often does), but this might be too confusing.
Sorry not to use ggplot2, but I haven't sat down to try to figure
it out yet ....
View this message in context: http://www.nabble.com/3d-barplot-in-rgl-tf4517380.html#a12891221 Sent from the R help mailing list archive at Nabble.com.
Transition matrices are Markov transition matrices among different life stages of organisms -- in the simplest case (Leslie matrices,
Ben, Thanks for your clear explanation and plot examples. I like the dotplots alot and added a few modifications below. Since I often compare rows and columns as well as groups of elements representing growth (lower left trianlge), stasis (diagonal), fertility etc., I like to preserve the matrix structure in the plot if possible.
library(popbio) example(teasel) ## shows 2 plots -- heatmap and stair-step A <- tea$sensitivities ## z <- as.data.frame.table(A)
#switch labels here- stage at time t in columns and fate at time t+1 in rows
names(z) <- c("To","From","Sensitivity")
# reverse order on rows to match matrix
z$To <- ordered(z$To, levels = rev(levels(z$To)))
dotplot(To~Sensitivity|From, data=z,
scales=list(alternating=c(1,0), tck=c(1,0)), layout=c(6,1), aspect=2)
# or log-scale
dotplot(To~Sensitivity|From,data=z,scales=list(x=list(log=TRUE)), as.table=TRUE)
Thanks again,
Chris