As you already said - 3D barcharts are "bad". You can't do it directly in ggplot2 but here is a possible workaround for this.
First, make new data frame that contains levels of clarity and corresponding count for each level.
library(plyr)
df2<-ddply(diamonds,.(clarity),nrow)
Then in ggplot()
call use new data frame and clarity
as x values and V1
(counts) as y values and add geom_blank()
- this will make x axis with levels we need. Then add geom_rect()
to produce shading for bars - here xmin
and xmax
values are made as.numeric()
from clarity
and constant is added - for xmin
constant should be less than half of bars width and xmax
constant larger than half of bars width. ymin
is 0 and ymax
is V1
(counts) plus some constant. Finally add geom_bar(stat="identity")
above this shadow to plot actually barplot.
ggplot(df2,aes(clarity,V1)) + geom_blank()+
geom_rect(aes(xmin=as.numeric(clarity)-0.38,
xmax=as.numeric(clarity)+.5,
ymin=0,
ymax=V1+250),fill="green")+
geom_bar(width=0.8,stat="identity")