0
votes

I was using r to draw barplot(grouped) of 50 states, and due to the date is from 2005-2012, so I want to change the axis limit. Here is the code.

b<-read.csv("/Users/tori/Documents/Curry/breach 2.csv")
br<-data.frame(b$State,
           e=b$Effective,
           f=b$First)
View(br)
bb<-t(br[-1])
colnames(bb) <- br[, 1]

View(bb) #ok
bd<-data.frame(bb)
par(las=1,mar=c(3,9,1,1),cex.axis=0.55)
barplot(bb,beside=TRUE,horiz=TRUE,xlim=c(2004,2011))

And turn out to be like this, I'm really confusing. (I can't update picture, but it seems that the area out of the limit still have the graph.

dput(head(bb)) structure(c(0L, 2006L, 2009L, 2006L, 2006L, 2005L, 2005L, 2005L, 2003L, 2005L, 2006L, 2005L, 2006L, 2005L, 2005L, 2005L, 2007L, 2005L, 2005L, 2005L, 2005L, 2005L, 2007L, 2005L, 2006L, 2005L, 2006L, 2005L, 2006L, 2005L, 2008L, 2005L, 2006L, 2006L, 0L, 2005L, 2006L, 2006L, 2006L, 2006L, 2008L, 2006L, 2007L, 2005L, 2007L, 2005L, 2006L, 2005L, 2011L, 2006L, 2009L, 2005L, 2006L, 2005L, 2006L, 2005L, 2005L, 2005L, 2007L, 2006L, 2006L, 2005L, 0L, 2006L, 2005L, 2005L, 2005L, 2005L, 2005L, 2008L, 2006L, 2005L, 2006L, 2005L, 2007L, 2005L, 2006L, 2005L, 0L, 2010L, 2006L, 2005L, 2009L, 2006L, 0L, 2007L, 2005L, 2005L, 2009L, 2005L, 2007L, 2005L, 2007L, 2005L, 2008L, 2005L, 2005L, 2005L, 2008L, 2006L, 2006L, 2005L, 2007L, 2009L), .Dim = c(2L, 52L), .Dimnames = list(c("e", "f" ), c("Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "District of Columbia", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Puerto Rico", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming")))

1
Please post dput(head(bb)) so we can see what the data look like and what classes it is stored in. Just edit it into your question.Gregor Thomas
If the variable is either a Date or a factor variable, then you could be making incorrect assumption about what the 'xlim' argument is really doing.IRTFM

1 Answers

0
votes

You can easily change axis limits using barplot(...,xlim = c(-1, 1), ylim = c(-1, 1)) Where xlim is for x-axis and ylim for y-axis.