R - Making ggplot work well for 2-color printing?

I make a lot of graphics for scientific journals, so I prefer to use the basic plot

R toolkit , which creates simple graphics that look professional in a two-color format. But sometimes I need more convenient functionality like ggplot

.

How can I generate graphics ggplot

with the "look and feel" functionality of the basic R GUI, or otherwise print in two color formats?

+3


source to share


1 answer


For complete control, you can create a "theme" function that will apply to your plots based on a wide range of graphics options ggplot2

.

The function below is not exhaustive, but it does make many subtle changes to the basic ggplot theme. All parameters can be easily changed. For example, change the font family (here "Helvetica"). Or move the title up and down using the parameter vjust

plot.title

.

myTheme <- function() {
theme(panel.border = element_blank(),
    panel.grid.minor = element_line(colour ='white'),
    panel.grid.major = element_line(colour = 'white'),
    panel.background = element_rect(fill = '#ededed', color = '#ededed'),
    plot.background = element_rect(fill = 'white', color = 'white'),
    plot.margin = unit(c(2.5, 2.5, 2.5, 2.5), 'cm'),
    plot.title = element_text(family = 'Helvetica', face ='bold', vjust=4, size=12, colour='#292929'),
    axis.title.y = element_text(family = 'Helvetica', size = 12, vjust = 1.5, face='bold', colour='#292929'),
    axis.title.x = element_text(family = 'Helvetica', size = 12, vjust = -1.5, face='bold',colour='#292929'),
    axis.text.y = element_text(family = 'Helvetica', size = 11, colour = '#292929'),
    axis.text.x = element_text(family='Helvetica', size = 11, colour='#292929'),
    axis.ticks.y = element_line(colour = 'white'),
    axis.ticks.x = element_line(colour = 'white'))
}

      

I personally prefer to have more space in the margins of the plot. To do this, you need:

install.packages('grid')
library(grid)

      

This package allows you to adjust the parameter plot.margin

.



Using this function is very simple. You just add it to the end of your ggplot code. Properly.

ggplot(mtcars, aes(disp, mpg)) + 
geom_point() +
ggtitle('Mtcars Plot') +
myTheme()

      

And as correctly stated in the comments above, by adding options scale_fill_grey()

or scale_colour_grey()

to your ggplot code as appropriate, you can control the grayscale.

With a theme like this, your plots will be as minimal as below and more consistent with the basic plots. For more details on how to control theme elements in more detail, see here: ggplot 2 theme control

Minimal Mtcars Plot

0


source







All Articles