1

Somehow I can't seem to get the labels to show up on my plot in the code below. Otherwise the figure looks fine, and the axes show up fine if I don't use the text option, but I'm trying to rotate the x-axis 45 degrees to make it more readable.

  png( file=fn,units='in', width=7,height=7,pointsize=10, res=350,type='cairo')
  pts = c(19, 22, 24)
  lns = c(1, 3, 1)
  cols = c("grey10", "grey10",  "grey20")
  yrange = c(0, 12760)
  xrange = c(1978, 2015)
  xrange[1] = xrange[1]
  xrange[2] = xrange[2]
  xlabels = seq(xrange[1]+1, xrange[2], 2)

  m=1; plot( uyrs, l[,m],  type="b", ylab="Landings (t)", xlab="Year", col=cols[m], lwd=4, lty=lns[m], pch=pts[m], xaxt="n", xlim=xrange, ylim=yrange)
  m=2; points(uyrs, l[,m], type="b", col=cols[m], lwd=3, lty=lns[m], pch=pts[m])
  m=3; points(uyrs, l[,m], type="b", col=cols[m], lwd=3, lty=lns[m], pch=pts[m])
  axis(1, at=xlabels, labels=FALSE)
  text(x=xlabels, labels=xlabels, srt=45, adj=1, xpd=TRUE)
  legend(x=1980, y=8500, c("N-ENS", "S-ENS", "4X"), bty="n", lty=lns, lwd=3, pch=pts, col=cols, cex=1.4 )

  dev.off()

Here is the plot I am trying to add labels to. The tic marks show up at the proper locations

GreenlawM
  • 55
  • 1
  • 11
  • http://stackoverflow.com/questions/1828742/rotating-axis-labels-in-r does this help? :) – Gewure Jan 06 '16 at 19:05
  • Your code doesn't work : `object 'l' not found` , `object 'uyrs' not found` – HubertL Jan 06 '16 at 19:17
  • @Gewure, no the labels need to be rotated 45 degrees, rather than vertical, therefore the simple way won't work. There are numerous examples that suggest using the text() option, but I can't seem to get anything to show up. I will add some code so it works properly...right now the dataset is not linked in – GreenlawM Jan 06 '16 at 19:28
  • 1
    Set your y for the text function `y=par('usr')[3]`. From there + or - to adjust for the positioning. Often I use `adj = c( 1.1 , 1.1 )` as well, then you get an x and a y adjustment that makes the user parameter 3 work a little nicer. A follow up here: your labels are not showing up because y will default to 0, which is under your plot. – Badger Jan 06 '16 at 19:41
  • works perfect @Badger, thanks!!! – GreenlawM Jan 06 '16 at 20:22

0 Answers0