barchart in R using lattice

2020-07-19 05:32发布

问题:

This is my code:

d<-data.frame(column1=rep(Names, each=1),column2=rep(c("one"),1),column3=values)
barchart(column3 ~ column1, groups=column2, d, auto.key = list(columns = 1))

One of my values is negative. On my picture I see all the bars starting from negative values and growing up to their values, but I want to see all the bars starting at 0 (one bar has revers direction).

How can I do this?

I'm not sure about lattice, any other way is ok. I tried barplot, it plots in the right way, but my lables are too long, so when I make the font smaller - I can't read anithyng because of its style.

回答1:

Use the origin argument:

barchart(column3 ~ column1, groups=column2, d, auto.key = list(columns = 1), origin=0)