A high quality plot

I’ll keep this post short and sweet. Here’s some code to get a really nice looking plot in R. It has a high pixel count to produce a high resolution output that can be used in a word document. Because of this, the size of everything in the plot (axes, points, text, axis labels, etc) has to be increased. I have skipped my normal commentary and instead left comments in the code. If you have any questions, leave a comment. Hope this helps!!

##First let's grab a dataset from the R library
#if we look at the data type 
#We need to convert from a "time series" object to a "matrix" to plot it
temp = as.matrix(nottem)
data =  matrix(temp, ncol=12, byrow = TRUE)
colnames(data) = c("jan", "feb", "mar", "apr", "may", "jun",
                   "jul", "aug", "sep", "oct", "nov", "dec")
#This tells you where you data is stored
#This is important because we will store our plot here
#Calculate the monthly means
monthlymean<-apply(data, 2, FUN=mean)
#Make boxplots of the observed monthly data 

          xaxt='n', xlab="", ylab="",
          main="", cex.main=2, cex.lab=3, cex.axis=3, outcex=2)
points(monthlymean, pch=24, col="black", bg="red", cex=4)

axis(side=1, at=1:12, labels=FALSE, tick=TRUE, cex.axis=3, tck=-0.01)
mtext("Temperature (Fahrenheit)",side=2,las=0,cex=3.5,line=4.5)

legend("topleft",pch=c(24), c("Mean Observed Precipitation"),
       col=c("black"),pt.bg=c("red"), cex=3)
mtext("Average Monthly Temperatures at Nottingham", side=3, line=4.5, cex=4)
mtext("1920-1939", side=3, line=0.6, cex=3.5)

A nice plot


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s