I'm aware that plotting in 3D is not the best way to represent data. However, my supervisor (a non statistican) has requested I do it so here I am. I'm trying to plot counts for how many documents contain singles, pairs and triples of certain key words.
I've managed to plot the data in a 2D fashion, which I'd argue is best, but for my meeting next week I'd like to be able to plot it in 3D too, even if it's to justify why plotting in 3D isn't suitable. I've attached code to reproduce my data as well as the plots I've managed to get so far.
Ideally, I would like a combination of the two plots.
2D stacked bar plot:
3D bar plot:
My data:
b <- c(336,358,168,143,NA,358,161,142,NA,NA,168,100,NA,NA,NA,143)
c <- c(358,358,161,142,NA,3114,2200,2205,NA,NA,2200,842,NA,NA,NA,2205)
f <- c(163,161,163,100,NA,2200,2200,842,NA,NA,3388,899,NA,NA,NA,899)
e <- c(143,142,100,143,NA,2205,842,2205,NA,NA ,899,899,NA,NA,NA,2754)
ndimdata <- array(c(b, c, f, e),
c(4, 4, 4),
list(c("hmasm", "s", "ppng", "cdr"),
c("hmasm", "s", "ppng", "cdr"),
c("hmasm", "s", "ppng", "cdr")))
What the data looks like:
> ndimdata
, , hmasm
hmasm s ppng cdr
hmasm 336 NA NA NA
s 358 358 NA NA
ppng 168 161 168 NA
cdr 143 142 100 143
, , s
hmasm s ppng cdr
hmasm 358 NA NA NA
s 358 3114 NA NA
ppng 161 2200 2200 NA
cdr 142 2205 842 2205
, , ppng
hmasm s ppng cdr
hmasm 163 NA NA NA
s 161 2200 NA NA
ppng 163 2200 3388 NA
cdr 100 842 899 899
, , cdr
hmasm s ppng cdr
hmasm 143 NA NA NA
s 142 2205 NA NA
ppng 100 842 899 NA
cdr 143 2205 899 2754
My code:
library(ggplot2)
library(reshape2)
df <- melt(ndimdata, id.vars=c("keywords1", "keywords2"))
#2d stacked plot
ggplot(df, aes(x = Var2, y = value, fill = Var3)) +
geom_bar(stat = 'identity', position = 'stack') +
facet_grid(~ Var1)
library(latticeExtra)
#3d non-stacked plot
cloud(df$value ~ df$Var1 + df$Var3, df,
panel.3d.cloud = panel.3dbars,
xbase=0.4, ybase=0.4, scales=list(arrows=FALSE, col=1),
par.settings = list(axis.line = list(col = "transparent")),
drape=TRUE)