align 0 in the same line in lattice

谁都会走 提交于 2019-12-25 06:37:16

问题


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.


回答1:


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)



来源:https://stackoverflow.com/questions/21385686/align-0-in-the-same-line-in-lattice

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!