Color, line type, and point shape in ggplot2 diagrams

Install required packages

ggplot2, ggbeeswarm

Simulate data

Data needs to be in long format such that color / line type / point shape can be controlled via variables.

Color

Point / line color

plot of chunk ggplot_aes01
plot of chunk ggplot_aes01
plot of chunk ggplot_aes03
plot of chunk ggplot_aes03

Fill color

plot of chunk ggplot_aes04
plot of chunk ggplot_aes04
plot of chunk ggplot_aes05
plot of chunk ggplot_aes05

Point shape

plot of chunk ggplot_aes06
plot of chunk ggplot_aes06

Line type

  sex   group   mood
1   f control  87.04
2   m control  75.52
3   f placebo 110.06
4   m placebo  90.22
5   f  treatA 133.30
6   m  treatA 107.18
7   f  treatB  97.02
8   m  treatB 116.68
plot of chunk ggplot_aes07
plot of chunk ggplot_aes07

Further online resources

See Cookbook for R: ggplot2 diagrams for many detailed examples of ggplot2 diagrams.

Detach (automatically) loaded packages (if possible)

Get the article source from GitHub

R markdown - markdown - R code - all posts