I think you can get what you want simply with a stacked barchart.
library(lattice)
barchart(b~a, data=test, col=c("#00FFFF"), group=d, stack=TRUE)
Question
This is the code for ggplot2
library(ggplot2)
test <- data.frame(a=c('1','1','2','2'),b=c(2,-2,4,-3),d=c('m','n','m','n'))
p <- ggplot(test,aes(a,b))
p + geom_bar(position=position_dodge(),stat='identity',
fill='deeppink',colour='black',width=0.5)
for some reason, I need to re-draw the figure with lattice
,
library(lattice)
a<-barchart(b~a,data=test)
so I want the same alignment as in ggplot2
by using lattice
.
La solution
I think you can get what you want simply with a stacked barchart.
library(lattice)
barchart(b~a, data=test, col=c("#00FFFF"), group=d, stack=TRUE)