Page last updated: 04 May, 2019

 

Examples

One variable

##### line plot
ggplot(data = movies, 
       aes(x = votes, y = rating)) +
  geom_line(aes(x = votes, y = rating),
            color = discrete_wes_pal[1]) +
  my_theme() 

One variable shown by colour

##### line plot - with groups defined by colour and size
ggplot(data = movies, 
       aes(x = votes, y = rating)) +
  geom_line(aes(colour = Genre)) +
  scale_color_manual(values = discrete_wes_pal) +
  guides(colour = guide_legend(override.aes = list(size = 5),
                               title = "",
                               label.hjust = 0,
                               label.vjust = 0.5)) +
    my_theme() 

One variable shown by size

##### line plot - with groups defined by colour and size
ggplot(data = movies, 
       aes(x = votes, y = rating)) +
  geom_line(aes(size = Genre),
            color = discrete_wes_pal[1]) +
  guides(size = guide_legend(title = "",
                             label.hjust = 0,
                             label.vjust = 0.5)) +
  my_theme()

One variable shown by colour and size

##### line plot - with groups defined by colour and size
ggplot(data = movies, 
       aes(x = votes, y = rating)) +
  geom_line(aes(colour = Genre, size = Genre)) +
  scale_color_manual(values = discrete_wes_pal) +
  guides(colour = guide_legend(override.aes = list(size=5),
                               title = "",
                               label.hjust = 0,
                               label.vjust = 0.5)) +
    my_theme() 

Two variables shown by colour and size

## line plot - with groups defined by colour and rating by size
ggplot(data = movies, 
       aes(x = votes, y = rating)) +
  geom_line(aes(colour = Genre, size = rating)) +
  scale_color_manual(values = discrete_wes_pal) +
  guides(colour = guide_legend(override.aes = list(size=5),
                               title = "",
                               label.hjust = 0,
                               label.vjust = 0.5)) +
  guides(size = guide_legend(label.hjust = 0,
                             label.vjust = 0.5)) +
    my_theme() 

LS0tCnRpdGxlOiAiTGluZSBwbG90cyIKb3V0cHV0OgogIGh0bWxfZG9jdW1lbnQ6CiAgICB0b2M6IGZhbHNlCiAgICBudW1iZXJfc2VjdGlvbnM6IGZhbHNlCiAgICBkZl9wcmludDogcGFnZWQKICAgIGNvZGVfZG93bmxvYWQ6IHRydWUKICAgIGhpZ2hsaWdodGVyOiBudWxsCi0tLQoKYGBge3Igc2V0dXAsIGV2YWw9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