How to make 3D graphics with categorical data in R?

I am trying to create a 3D graph based on categorical data, but have not found a way.

It is easy to explain. Consider the following sample data (a real example is more complex, but it comes down to this), showing the relative risk of something with a breakdown by income and age, both categorical data.

I want to display this on a three-dimensional graph (similar to the idea of http://demos.devexpress.com/aspxperiencedemos/NavBar/Images/Charts/ManhattanBar.jpg ). I looked at the scatterplot3d package, but this is only for scatter charts and does not process categorical data. I managed to make a 3d chart, but it shows points instead of three-dimensional bars. There is no chart type for me. I also tried the rgl package, but no luck. I have been working in search engines for more than an hour and have not found a solution. I have a copy of ggplot2's book - Elegant Graphics for Data Analysis, but ggplot2 does not have this type of chart.

Can I use another free app? OpenOffice 3.2 also does not have this diagram.

Thanks for any tips.

Age,Income,Risk young,high,1 young,medium,1.2 young,low,1.36 adult,high,1 adult,medium,1.12 adult,low,1.23 old,high,1 old,medium,1.03 old,low,1.11 
+4
source share
3 answers

I'm not sure how to make a 3D diagram in R, but there are other, more efficient ways to represent this data than with a 3D diagram. 3D charts make interpretation difficult because the heights of the bars are then distorted by the 3D perspective. In this chart example, it is difficult to say whether Wisconsin in 2004 is actually higher than Wisconsin 2001, or if it is a prospect effect. And if it is higher, how much is it?

Since both Age and Income have significant orders, it would be terrible to make a linear graph. ggplot2 code:

 ggplot(data, aes(Age, Risk, color = Income))+ geom_line(aes(group = Income)) 

Or you could make a heat map.

 ggplot(data, aes(Age, Income, fill = Risk)) + geom_tile() 
+6
source

Like the others, the proposed options are best presented, but this should help you get started if you want something similar to what you had.

 df <- read.csv(textConnection("Age,Income,Risk young,high,1 young,medium,1.2 young,low,1.36 adult,high,1 adult,medium,1.12 adult,low,1.23 old,high,1 old,medium,1.03 old,low,1.11 ")) df$Age <- ordered(df$Age, levels=c('young', 'adult', 'old')) df$Income <- ordered(df$Income, levels=c('low', 'medium', 'high')) library(rgl) plot3d(Risk ~ Age|Income, type='h', lwd=10, col=rainbow(3)) 

This will create flat rectangles. For example, to create nice lines, see demo(hist3d) .

+1
source

You can find the starting point here , but you need to add more lines and some rectangles to get the plot you posted.

0
source

All Articles