This vignettes demonstrates how to customize plots created with the
plot()-method of the ggeffects-package.
plot() returns an object of class ggplot, so it is easy to apply further modifications to the resulting plot. You may want to load the ggplot2-package to do this:
Let’s start with a default-plot:
The simplest thing is to change the titles from the plot, x- and y-axis. This can be done with
The legend-title can also be changed using the
labs()-function. The legend in ggplot-objects refers to the aesthetic used for the grouping variable, which is by default the
colour, i.e. the plot is constructed in the following way:
labs() changes the legend-title:
For black-and-white plots, the group-aesthetic is mapped to different linetypes, not to different colours. Thus, the legend-title for black-and-white plots can be changed using
If the variable on the x-axis is discrete for a black-and-white plot, the group-aesthetic is mapped to different shapes, so following code must be used to change the legend title:
The x-axis for plots returned from
plot() is always continuous, even for discrete x-axis-variables. The reason for this is that many users are used to plots that connect the data points with lines, which is only possible for continuous x-axes. You can do this using the
Since the x-axis is continuous (i.e.
ggplot2::scale_x_continuous()), you can use
scale_x_continuous() to modify the x-axis, and change breaks, limits or labels.
... are passed down to
log.y = TRUE), so you can control the appearance of the y-axis by putting the arguments directly into the call to
The legend labels can also be changed using a
scale_*()-function from ggplot. Depending on the color-setting (see section Changing the Legend Title), following functions can be used to change the legend labels:
Since you overwrite an exising “color” scale, you typically need to provide the
palette-argument, to manuall set the colors, linetypes or shapes.
For plots using default colors:
For black-and-white plots: