Site icon R-bloggers

Bare-bones intro to Plotting options in R

[This article was first published on Isomorphismes, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

If you’re using base::plot in R for the first time (for example if you do plot(pima) or plot(faithful) (use ??pima if you can’t find the dataset)) you may have looked at ?plot (2 page help file) or ?par (12 page help file) to figure out what’s going on.

> plot(faithful, pch=19, col=rgb(.1,.1,.1,.5), cex=.6)

Firstly: what is par? When you type par( lwd=3, col="#333333", yaxt="n"), it will open an empty box that will hold your next plot( dnorm, -3, 3). You can run different plots in the box and as long as you don’t close it, the line-width will be 3 times bigger than default, and the colour will be dark-grey.

There are a lot of plotting options. Here are the ones I use regularly:

Here are the ones I use less regularly, but still more than weird stuff like oma, mex, mai, etc.

Most of these can be done inside of plot( dpois, 0, 15, lwd = 3) or beforehand in a par(lwd=3); plot( dpois, 0, 15). With par(new=TRUE) and par(mfrow=c(2,2)), though, you need to do them in a par() beforehand.

If you forget what the colours or the pch shapes are, do this: plot( 1:25, pch=1:25, col=1:25). You’ll get this:

So basically, you only want pch=19 and sometimes pch=20 or pch=15, like I said.

One more thing you might like to learn is how to colour important data points red and normal ones grey. See this.

To leave a comment for the author, please follow the link and comment on their blog: Isomorphismes.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.