Hey, I am trying to create barplot of abundances over time (in days). The period is over 171 days, so I don't want to have all labels there but only the first day of the month. I couldn't find anything like this on the forum yet. Mostrly it's about year to year data. This is the relevant part of my table: datum month abundance 26/03/11 March 1 27/03/11 March 0 28/03/11 March 1 29/03/11 March 0 30/03/11 March 0 31/03/11 March 0 1/04/11 April 0 2/04/11 April 0 3/04/11 April 0 ... 9/09/11 September 1 I tried making a sequence: hatch$axis.ticks2=seq(from=hatch$datum[1],to=hatch$datum[171], by=30) But this sequence is too short to use the names.arg function. Next, I tried more ideas from this forum that might work. But the best I got was by just replacing the day by a month and reducing the size of the tickmarks. Or by blanking excessive labels in R commander. But this is really poor substitute of what I actually want. Furthermore, in the end I want the labels vertical to match other graphs (las=2), but when doing that my labels become so dense it's basically one black blur. bar=barplot(abundance, col="black",xlab="", ylim=c(0,120), axisnames=T, ylab="Total fish",axis.lty=1) axis(1,at=bar, tcl=-0.01, las=1,lab=hatch$month,cex.axis=0.8) I hope I made my problem clear. Thank you. -- View this message in context: http://r.789695.n4.nabble.com/barplot-tp4631070.html Sent from the R help mailing list archive at Nabble.com.
On 05/23/2012 09:34 PM, bets wrote:> Hey, > > I am trying to create barplot of abundances over time (in days). The period > is over 171 days, so I don't want to have all labels there but only the > first day of the month. I couldn't find anything like this on the forum yet. > Mostrly it's about year to year data. > > This is the relevant part of my table: > > datum month abundance > 26/03/11 March 1 > 27/03/11 March 0 > 28/03/11 March 1 > 29/03/11 March 0 > 30/03/11 March 0 > 31/03/11 March 0 > 1/04/11 April 0 > 2/04/11 April 0 > 3/04/11 April 0 > ... > 9/09/11 September 1 > > I tried making a sequence: > hatch$axis.ticks2=seq(from=hatch$datum[1],to=hatch$datum[171], by=30) > But this sequence is too short to use the names.arg function. > Next, I tried more ideas from this forum that might work. But the best I got > was by just replacing the day by a month and reducing the size of the > tickmarks. Or by blanking excessive labels in R commander. But this is > really poor substitute of what I actually want. Furthermore, in the end I > want the labels vertical to match other graphs (las=2), but when doing that > my labels become so dense it's basically one black blur. > > bar=barplot(abundance, col="black",xlab="", ylim=c(0,120), axisnames=T, > ylab="Total fish",axis.lty=1) > axis(1,at=bar, tcl=-0.01, las=1,lab=hatch$month,cex.axis=0.8) >Hi bets, So you have 171 bars with most of them 0? If you want to use "barplot", drop the x axis: barplot(...,xaxt="n",...) and then display an x axis with, let's see, seven labels. Something like: axis(1,at=seq(as.Date("2011-03-15"),as.Date("2011-09-09"),by=30), labels=month.abbr[3:9]) If they don't all display, try "staxlab" in the plotrix package. Jim
Thank you for the answer. I tried the first suggestion, but that didn't work (length didn't match again), unless I'm doing something wrong. The stacklab function is nice, but still I'm having way to much labels. Maybe the actual graph makes it more clear: http://r.789695.n4.nabble.com/file/n4631082/bad.png -- View this message in context: http://r.789695.n4.nabble.com/barplot-tp4631070p4631082.html Sent from the R help mailing list archive at Nabble.com.
Hello, Would the following do it? # make the dates vector x <- seq(as.Date("2011-03-15"), as.Date("2011-09-09"), by="day") # this is the important part labs <- seq(min(x), max(x), by="month") # "month", not 30 labs <- format(labs, "%b") labs.pos <- round(seq(1, length(x), length.out=length(labs))) # make some abundance data set.seed(1) y <- rnorm(1e4) y <- hist(y, breaks=seq(min(y) - 0.5, max(y) + 0.5, length.out=180), plot=FALSE)$counts df1 <- data.frame(datum=x, abundance=y) barplot(df1$abundance, xaxt="n") axis(1, at=labs.pos, labels=labs) Hope this helps, Rui Barradas bets wrote> > Hey, > > I am trying to create barplot of abundances over time (in days). The > period is over 171 days, so I don't want to have all labels there but only > the first day of the month. I couldn't find anything like this on the > forum yet. Mostrly it's about year to year data. > > This is the relevant part of my table: > > datum month abundance > 26/03/11 March 1 > 27/03/11 March 0 > 28/03/11 March 1 > 29/03/11 March 0 > 30/03/11 March 0 > 31/03/11 March 0 > 1/04/11 April 0 > 2/04/11 April 0 > 3/04/11 April 0 > ... > 9/09/11 September 1 > > I tried making a sequence: > hatch$axis.ticks2=seq(from=hatch$datum[1],to=hatch$datum[171], by=30) > But this sequence is too short to use the names.arg function. > Next, I tried more ideas from this forum that might work. But the best I > got was by just replacing the day by a month and reducing the size of the > tickmarks. Or by blanking excessive labels in R commander. But this is > really poor substitute of what I actually want. Furthermore, in the end I > want the labels vertical to match other graphs (las=2), but when doing > that my labels become so dense it's basically one black blur. > > bar=barplot(abundance, col="black",xlab="", ylim=c(0,120), axisnames=T, > ylab="Total fish",axis.lty=1) > axis(1,at=bar, tcl=-0.01, las=1,lab=hatch$month,cex.axis=0.8) > > I hope I made my problem clear. > Thank you. >-- View this message in context: http://r.789695.n4.nabble.com/barplot-tp4631070p4631093.html Sent from the R help mailing list archive at Nabble.com.