knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) library(ectrlplot) library(ggplot2)
ectrlplot
package?This is an R package, developed by the PRU team to make the process of creating publication-ready graphics in our in-house style, using R’s ggplot2
library, a more reproducible process.
The package is constisted of the following functions:
theme_pru()
to add the PRU style in the ggplot2 graphics
add_logo()
to add the EUROCONTROL logo and the source
pru_pal()
to see the colour palette of the PRU team
scale_color_pru()
, scale_colour_pru()
& scale_fill_pru()
to use the colour palette of the PRU team
knitr::include_graphics('pru-pal.png', dpi = NA)
This package can be used to give to the graphics made by the PRU team a consistent customized look.
The following examples will help you understand how to use ectrlplot
package and its components step by step.
Let's start with a basic scatterplot example.
p1 <- ggplot(mtcars, aes(wt, mpg)) + geom_point() + labs(title = 'Scatterplot example in ggplot2', subtitle = 'A plot that is only useful for demonstration purposes') p1
p1 + theme_pru()
Use the PRU color palette by adding scale_color_pru()
, scale_colour_pru()
or scale_fill_pru()
.
library(scales) p2 <- ggplot(mpg[1:48,], aes(displ, hwy, colour = class)) + geom_point() + theme_pru() + scale_color_pru() + labs(title = 'Scatterplot example in ggplot2', subtitle = 'A plot that is only useful for demonstration purposes') p2
If you want to modify some components of the theme_pru()
,
use theme()
and add your preferences.
In this example, the Y axis line is added and the Y axis grid lines in the panel are removed.
See how to modify components of a theme.
p3 <- p2 + theme(axis.line.y = ggplot2::element_line(colour = "#D5D5D5", size = 1.2, linetype = "solid", lineend = "round"), panel.grid.major.y = ggplot2::element_blank()) p3
Finish the plot by adding the logo, the source and the filepath that you want it to be saved.
The EUROCONTROL logo is the default in this package. If you want to use your own logo, modify the function by adding the parameter logo_image_path.
add_logo(plot_name = p3, source = "Source: My source", save_filepath = "thisismyplot.png", width_pixels = 640, height_pixels = 450)
Now, let's see how to use the ectrlplot
package in ggplot2 bar chart.
g1 <- ggplot(mpg[1:108,], aes(class)) + geom_bar() + labs(title = 'Bar chart example in ggplot2', subtitle = 'A plot that is only useful for demonstration purposes') g1
g1 + theme_pru()
Now, we are grouping the data by class.
g2 <- ggplot(mpg[1:108,], aes(class)) + geom_bar(aes(fill = manufacturer)) + theme_pru() + labs(title = 'Bar chart example in ggplot2', subtitle = 'A plot that is only useful for demonstration purposes') g2
Use the PRU color palette by adding scale_fill_pru()
.
g3 <- g2 + scale_fill_pru() g3
Finish the plot by adding the logo, the source and the filepath that you want it to be saved.
add_logo(plot_name = g3, source = "Source: My source", save_filepath = "thisismyplot.png", width_pixels = 640, height_pixels = 450)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.