Examples for 'ggplot2::scale_colour_manual'


Create your own discrete scale

Aliases: scale_colour_manual scale_fill_manual scale_size_manual scale_shape_manual scale_linetype_manual scale_alpha_manual scale_discrete_manual scale_color_manual

Keywords:

### ** Examples

p <- ggplot(mtcars, aes(mpg, wt)) +
  geom_point(aes(colour = factor(cyl)))
p + scale_colour_manual(values = c("red", "blue", "green"))
plot of chunk example-ggplot2-scale_colour_manual-1
# It's recommended to use a named vector
cols <- c("8" = "red", "4" = "blue", "6" = "darkgreen", "10" = "orange")
p + scale_colour_manual(values = cols)
plot of chunk example-ggplot2-scale_colour_manual-1
# You can set color and fill aesthetics at the same time
ggplot(
  mtcars,
  aes(mpg, wt, colour = factor(cyl), fill = factor(cyl))
) +
  geom_point(shape = 21, alpha = 0.5, size = 2) +
  scale_colour_manual(
    values = cols,
    aesthetics = c("colour", "fill")
  )
plot of chunk example-ggplot2-scale_colour_manual-1
# As with other scales you can use breaks to control the appearance
# of the legend.
p + scale_colour_manual(values = cols)
plot of chunk example-ggplot2-scale_colour_manual-1
p + scale_colour_manual(
  values = cols,
  breaks = c("4", "6", "8"),
  labels = c("four", "six", "eight")
)
plot of chunk example-ggplot2-scale_colour_manual-1
# And limits to control the possible values of the scale
p + scale_colour_manual(values = cols, limits = c("4", "8"))
plot of chunk example-ggplot2-scale_colour_manual-1
p + scale_colour_manual(values = cols, limits = c("4", "6", "8", "10"))
plot of chunk example-ggplot2-scale_colour_manual-1

[Package ggplot2 version 3.3.6 Index]