docs/appendix-e-plotstyles.md

Styling Plots {#plotstyle}

Aesthetics

Colour/Fill

The colour argument changes the point and line colour, while the fill argument changes the interior colour of shapes. Type colours() into the console to see a list of all the named colours in R. Alternatively, you can use hexadecimal colours like "#FF8000" or the rgb() function to set red, green, and blue values on a scale from 0 to 1.

Hover over a colour to see its R name.

.colordemo { list-item-style: none; padding: 0; margin: 0;} .colordemo li, main ul.colordemo > li:first-child { display: inline-block; border: 0.25px solid black; margin: 0px; padding: 1.3em 0.2em 0.2em 1.2em; } .colordemo li span { display: none; background-color: white; border: 0.25px solid black; padding: 0.25em 0.5em; border-radius: 0 1em 1em 1em; } .colordemo li:hover span { display: inline; position: absolute; }

Alpha

The alpha argument changes transparency (0 = totally transparent, 1 = totally opaque).

Varying alpha values.

(\#fig:alpha-demo)Varying alpha values.

Shape

The shape argument changes the shape of points.

The 25 shape values

(\#fig:shape-demo)The 25 shape values

Linetype

You can probably guess what the linetype argument does.

The 6 linetype values at different sizes.

(\#fig:linetype-demo)The 6 linetype values at different sizes.

Palettes

Discrete palettes change depending on the number of categories.

Default discrete palette with different numbers of levels.

(\#fig:unnamed-chunk-3)Default discrete palette with different numbers of levels.

Viridis Palettes

Viridis palettes are very good for colourblind-safe and greyscale-safe plots. The work with any number of categories, but are best for larger numbers of categories or continuous colours.

Discrete Viridis Palettes

Set discrete viridis colours with scale_colour_viridis_d() or scale_fill_viridis_d() and set the option argument to one of the options below. Set direction = -1 to reverse the order of colours.

Discrete viridis palettes.

(\#fig:unnamed-chunk-4)Discrete viridis palettes.

::: {.info data-latex=""} If the end colour is too light for your plot or the start colour too dark, you can set the begin and end arguments to values between 0 and 1, such as scale_colour_viridis_c(begin = 0.1, end = 0.9). :::

Continuous Viridis Palettes

Set continuous viridis colours with scale_colour_viridis_c() or scale_fill_viridis_c() and set the option argument to one of the options below. Set direction = -1 to reverse the order of colours.

Continuous viridis palettes.

(\#fig:unnamed-chunk-5)Continuous viridis palettes.

Brewer Palettes

Brewer palettes give you a lot of control over plot colour and fill. You set them with scale_color_brewer() or scale_fill_brewer() and set the palette argument to one of the palettes below. Set direction = -1 to reverse the order of colours.

Qualitative Brewer Palettes

These palettes are good for categorical data with up to 8 categories (some palettes can handle up to 12). The "Paired" palette is useful if your categories are arranged in pairs.

Qualitative brewer palettes.

(\#fig:unnamed-chunk-6)Qualitative brewer palettes.

Sequential Brewer Palettes

These palettes are good for up to 9 ordinal categories with a lot of categories.

Sequential brewer palettes.

(\#fig:unnamed-chunk-7)Sequential brewer palettes.

Diverging Brewer Palettes

These palettes are good for ordinal categories with up to 11 levels where the centre level is a neutral or baseline category and the levels above and below it differ in an important way, such as agree versus disagree options.

Diverging brewer palettes.

(\#fig:unnamed-chunk-8)Diverging brewer palettes.

Themes

ggplot2 has 8 built-in themes that you can add to a plot like plot + theme_bw() or set as the default theme at the top of your script like theme_set(theme_bw()).

{ggplot2} themes.

(\#fig:unnamed-chunk-9){ggplot2} themes.

ggthemes

You can get more themes from add-on packages, like ggthemes. Most of the themes also have custom scale_ functions like scale_colour_economist(). Their website has extensive examples and instructions for alternate or dark version sof these themes.

{ggthemes} themes.

(\#fig:unnamed-chunk-10){ggthemes} themes.



PsyTeachR/reprores-v2 documentation built on Sept. 26, 2022, 10:06 a.m.