I’m having the code as like below. But I’m not getting all the x axis labels and it is not displaying in 45 degree when I try to have this in pdf. Since I’m new, Please help me correct this option.
pdf(file="figure.pdf", height=3.5, width=5, onefile=TRUE)
Runtime <- c(579,0,581,610,830,828,592,651,596,596,591,581,587,594,604,606,447,434,445)
Runtime
g_range <- range(0,Runtime)
g_range
plot(Runtime, type="o", col="blue", ylim=g_range,axes=FALSE, ann=FALSE)
lab=c('2011-07-20','2011-08-03','2011-08-10','2011-08-17','2011-08-24','2011-08-25','2011-08-27','2011-08-31','2011-09-07','2011-09-10','2011-09-14','2011-09-21','2011-09-28','2011-10-05','2011-10-06','2011-10-07','2011-10-13','2011-10-19','2011-10-31')
box()
lab
axis(1, at=1:19, lab=F)
text(axTicks(1), par("usr")[3] - 2, srt=45, adj=1, labels=lab, xpd=T, cex=0.8)
axis(2, las=1, at=500*0:g_range[2])
title(main="Runtime", col.main="red", font.main=4)
title(xlab="Build", col.lab=rgb(0,0.5,0))
title(ylab="MS", col.lab=rgb(0,0.5,0))
legend(1, g_range[2], c("AveElapsedTime"), cex=0.8, col=c("blue"), pch=21, lty=1);
dev.off()
When I run your code, I do not get the image you show. The problem is this line:
as
axTicks(1)returns:So what is happening is that your 19 labels are being plotted at those 3 locations.
If you want to plot at the locations of the ticks (
1:19) then:will work.
Here is a full example based on your code.
This might be better handled using function in the gridBase package though, which allows grid and base graphics to intermingle. The reason I say it might be better is that you can specify that the
ycoordinate be set in terms of numbers of lines rather that trying to work out a suitable value foryin terms of the plotted data.Here is an example:
Note this can be a bit picky on screen, rerunning the gridBase example on my R 2.13.2 install doesn’t produce any labels. Closing the device and then running the code afresh works though. I don’t think this should be a problem if you are drawing to a
pdf()device.