質問

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.

役に立ちましたか?

解決

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top