There are several approaches to
customising the plots produced by shape_plot(),
forest_plot() and volcano_plot(). These are,
in order of increasing complexity:
There are several key arguments available for customising plots. Most of these arguments can accept either a fixed value or the name of a column in the supplied data frame.
base_size sets the base font
size.base_line_size sets the base line
size.plotcolour sets the colour of non-data
elements of the plot.colour sets the colour of points in
shape_plot() and the colour of points and lines in
forest_plot().cicolour sets the colour of confidence
interval (CI) lines in shape_plot()fill sets the fill colour of points.
This only has an effect when using a shape that supports filling, such
as "square filled".point_colours sets the colours of
points according to their statistical significance and the sign of their
estimates in volcano_plot().shape sets the shape used for
points.col.bold in forest_plot()
specifies whether text is displayed in bold.col.diamond in
forest_plot() specifies whether an estimate and its CI are
displayed as a diamond.Note that col.bold and col.diamond must be
specified as column names. Diamonds can also be specified using the
diamond argument, which accepts a character vector of keys
identifying the estimates to display as diamonds.
The addaes arguments can be used to modify aesthetics in
the ggplot layers created by the functions, and the addarg
argument can be used to modify arguments. Both addaes and
addarg must be named lists of character strings, and the
names of the elements define where the aesthetics/arguments code is
added. The required names are shown in brackets in the comments of the
generated plot code
e.g. # Plot the point estimates [points].
For example, adjusting the position and appearance of panel headings:
forest_plot(list("a) Observational" = my_resultsA,
"b) Genetic" = my_resultsB),
col.key = "subgroup",
row.labels = row_labels,
addaes = list(panel.headings = "x = 0.5"),
addarg = list(panel.headings = c("size = 4.5",
"colour = 'navyblue'",
"hjust = 0")))Changing the appearance of the line at the null value:
forest_plot(list("a) Observational" = my_resultsA,
"b) Genetic" = my_resultsB),
col.key = "subgroup",
row.labels = row_labels,
addarg = list(nullline = c("linetype = 'dashed'",
"colour = 'darkorange'")))You can add additional ggplot objects to the plot with the
add argument. The argument should be a named list. Use the
name start to include objects in the ggplot immediately
after ggplot() (i.e. before anything else is added to the
ggplot) and use end to add to the end.
For example, to add additional geoms to the plot:
hr_geom <- geom_text(aes(label = auto_estcolumn),
size = 3,
hjust = 0,
nudge_y = 0.25,
colour = "red")
forest_plot(my_results,
estcolumn = FALSE,
add = list(start = hr_geom))Or to use theme to customise the plot:
my_theme <- theme(axis.text.x = element_text(colour = "purple",
angle = 45,
hjust = 1))
forest_plot(my_results,
add = list(end = my_theme))To add multiple objects, use a list:
my_parts <- list(hr_geom,
my_theme)
forest_plot(my_results,
estcolumn = FALSE,
add = list(end = my_parts))The add argument can also be used to replace parts of
the plot by using the names shown in brackets in the comments of the
generated plot code.
To remove a part of a plot, replace it with an empty list, for example:
Use the data.function argument in
forest_plot() to change the plot data immediately before
plotting.
For example, you can tweak the text in the generated estimates column:
my_func <- function(dfr) {
dfr$auto_estcolumn <- sub("\\(", "[", dfr$auto_estcolumn)
dfr$auto_estcolumn <- sub("\\)", "]", dfr$auto_estcolumn)
return(dfr)
}
forest_plot(my_results,
data.function = "my_func")