change_colors()
standardizes three methods for choosing color palettes for color or fill mapping, providing access to Brewer and Viridis palettes alongside custom choices.
Usage
change_colors(
x,
colorset = "brewer",
palette = 2,
kind = "qualitative",
direction = 1,
start = 1
)
Arguments
- x
A visualization made with
visualize()
- colorset
Either "brewer", "viridis", "okabe-ito", "dubois", or a vector of colors.
- palette
The number or name of palette (dependent on setting
colorset
to either "brewer" or "viridis")- kind
Used only for Brewer palettes to match numbered palette with the specific subset
- direction
The direction colors should be applied to the data. Setting to anything other than 1 will reverse the order.
- start
Useful for predefined colorsets from Okabe-Ito and Brewer to start from a color other than 1
See also
Other visualizing helpers:
plot_bigrams()
,
plot_doc_word_bars()
,
plot_doc_word_heatmap()
,
plot_hapax()
,
plot_htr()
,
plot_tf_idf()
,
plot_topic_bars()
,
plot_topic_distributions()
,
plot_topic_wordcloud()
,
plot_ttr()
,
plot_vocabulary()
,
visualize()
Examples
dubliners <- get_gutenberg_corpus(2814) |>
load_texts() |>
identify_by(part) |>
standardize_titles()
# Too many titles for categorical data.
selected_titles <- dubliners$doc_id |>
{\(x) x[grepl("^The |^A |^An ", x)]}() |>
unique()
dubliners2 <- dubliners |>
dplyr::filter(doc_id %in% selected_titles)
### CATEGORICAL DATA ##
# By default, ggplot2's palette is applied
dubliners2 |>
visualize()
# change_color() starts with Brewer's "Dark2" palette
dubliners2 |>
visualize() |>
change_colors()
# Other color sets and palettes can be chosen
dubliners2 |>
visualize() |>
change_colors(colorset = "okabe")
dubliners2 |>
visualize() |>
change_colors(colorset = "viridis", palette = "turbo")
dubliners2 |>
visualize() |>
change_colors(colorset = "brewer", palette = "Set1")
# Named cases can be highlighted
dubliners2 |>
visualize(inorder = FALSE) |>
change_colors(c(
rep("darkgray", 6),
"A Painful Case" = "blue"))
### SEQUENTIAL DATA ###
# By default, the "viridis" palette is applied
dubliners2 |>
visualize(type = "heatmap")
# change_colors() starts with Brewer's "BuGn" palette
dubliners2 |>
visualize(type = "heatmap") |>
change_colors()
#> Scale for fill is already present.
#> Adding another scale for fill, which will replace the existing scale.
# Palettes can be numbered or named
dubliners2 |>
visualize(type = "heatmap") |>
change_colors("viridis", palette = 6)
#> Scale for fill is already present.
#> Adding another scale for fill, which will replace the existing scale.
dubliners2 |>
visualize(type = "heatmap") |>
change_colors("viridis", palette = "mako")
#> Scale for fill is already present.
#> Adding another scale for fill, which will replace the existing scale.
### N-GRAMS ###
library(ggraph)
#> Loading required package: ggplot2
dubliners |>
add_ngrams() |>
visualize() |>
change_colors(c("#444488","orange"))
#> Scale for edge_colour is already present.
#> Adding another scale for edge_colour, which will replace the existing scale.