R has a great variety of plotting tools
(just to mention a few: the base
and e.g. lattice
packages building on
) and most R user has a preference for either of them.
I think all of you would agree with me: each package has its advantages and also disadvantages compared to the others
. And any senior R user could compile a lengthy list about this topic. But we do not intend to start a flame-war here
So I do not share my personal preferences in this post despite the fact that I was really puzzled while developing pander
: which graphics package should be supported with configurable options? As I planned to provide some
panderOptions in which the user could specify e.g. a color palette or the font family to be used in all of his plots
. But which library is used by most of R users? And how many potential users would I loose by choosing that only one?
In short, I decided to support all major graph engines, which means letting users specify their custom options and apply those to all
calls. This decision was a fast and promising one, the development was rather cumbersome
I came up with the idea to tweak evals further and apply options while evaluating R commands. This solution has the advantage of also tweaking e.g.
par before the actual commands (and even the plotting functions of
graphics too), but
evals got even more bloated. Well, I decided to take that trouble.
Now we have a bunch of options
is enabled in
(disabled by default not to freak out newcomers). You can fine-tune (
) the foreground, background and other color palettes, the global font size and even the font family used, the grid with optional minor ticks (even in
plots), the legend position and the angle of axis labels besides some other small tweaks.
I will only concentrate on the results below to keep this post short, if you would be interested in the sources, please check out the relevant branch on GitHub.
To show a brief demo of the new options, let us load the package and enable
First, let us check out how a default histogram looks like in the major graphics packages applied to
ggplot(df) + geom_histogram(aes(x = hp), binwidth = 50)
Please note that I have passed
binwidth to the
ggplot2 call not to abuse the comparison.
Doing the same with
evals (what is the default if you are using pander’s custom brew engine) results in:
evals('hist(df$hp, main = "Histogram in base R")')
evals('histogram(df$hp, main = "Histogram with lattice")')
evals('ggplot(df) + geom_histogram(aes(x = hp), binwidth = 50)
+ opts(title = "Histogram with ggplot2")')
I hope you would find the above graphs pretty similar
For a more detailed view on the results of
unify.images, please check out the package bundled demo (beside others) or the sources of the graphs.brew file.
To leave a comment
for the author, please follow the link and comment on their blog: rapporter
offers daily e-mail updates
news and tutorials
on topics such as: Data science
, Big Data, R jobs
, visualization (ggplot2
), programming (RStudio
, Web Scraping
) statistics (regression
, time series
) and more...
If you got this far, why not subscribe for updates
from the site? Choose your flavor: e-mail
, or facebook