ggExtra is Extra useful

April 3, 2016
By

(This article was first published on HighlandR, and kindly contributed to R-bloggers)

Amending plots with easy to remember syntax –

I love ggplot2, but I struggle to remember some of the specific syntax I need to get my plots looking the way I want, especially those relating to making tweaks in the theme settings.

Two of my most common changes are to rotate x axis labels, (so every date point is labeled), and removing the default grid lines.

The main reason I remove these is because I’m most often producing run or control charts, which need no additional distracting lines.

Typically to rotate the x-axis I need to add the following line to my code:

theme(axis.text.x = elementtext(angle=90, vjust=0.5))

And to remove (all) gridlines:

theme(panel.grid.minor=elementblank(),

panel.grid.major=elementblank())

Sometimes I only want to remove the minor lines:

theme(panel.grid.minor=elementblank())

The ggExtra package makes both simple with the rotateTextX and removeGrid functions.
Rotating the x axis labels now requires just:

rotateTextX()

and removing gridlines:

removeGrid()

By default removeGrid() removes all gridlines, (minor gridlines are always removed), and you can specify a particular axis if you wish .e.g. removeGridX() or removeGridY().

This is much easier to remember, and makes it easier to label all the dates on the x-axis.

You may also like to check out the cowplot package, which produces grid-free plots by default, and makes it easier to display multiple plots side by side.

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

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Sponsors

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)