0

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)

ggplot

for some reason, I need to re-draw the figure with lattice,

library(lattice)

a<-barchart(b~a,data=test)

lattice

so I want the same alignment as in ggplot2 by using lattice.

rcs
  • 67,191
  • 22
  • 172
  • 153
user36102
  • 275
  • 2
  • 3
  • 12

1 Answers1

3

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)

enter image description here

Aaron left Stack Overflow
  • 36,704
  • 7
  • 77
  • 142