library(here)
library(ggplot2)
library(RpalettePkg)
library(RplotterPkg)
current_dir <- here()
palette_file_path <- file.path(current_dir,"demos/data/diamonds_palette.rds")
# create a palette of colors for diamonds dataset by clarity
pal_colors <- c(
"I1" = "#d11141",
"SI2" = "#fa646f",
"SI1" = "#03ab3e",
"VS2" = "#25eb6a",
"VS1" = "#0723f5",
"VVS2" = "#4e65ec",
"VVS1" = "#f37735",
"IF" = "#f4e408"
)
RpalettePkg::create_palette(palette_path = palette_file_path, palette_colors = pal_colors)
# define a discrete fill scale palette
fill_scale_discrete <- RpalettePkg::get_fill_scale(
palette_path = palette_file_path,
scale_title = "diamonds_discrete_fill_scale"
)
# here is the default palette plot
diamond_plot_default <- RplotterPkg::create_bar_plot(
df = ggplot2::diamonds,
aes_x = "cut",
aes_fill = "clarity",
position = "dodge",
title = "Count of diamond 'cut' across of levels of 'clarity'",
rot_y_tic_label = TRUE,
y_limits = c(0, 5000),
y_major_breaks = seq(from =0,to = 5000, by = 500),
silent_NA_warning = TRUE
)
diamond_plot_default
# use "fill_scale_discrete$palette" palette for a bar plot
diamond_plot <- RplotterPkg::create_bar_plot(
df = ggplot2::diamonds,
aes_x = "cut",
aes_fill = "clarity",
palette_colors = fill_scale_discrete$palette,
position = "dodge",
title = "Count of diamond 'cut' across of levels of 'clarity'",
rot_y_tic_label = TRUE,
y_limits = c(0, 5000),
y_major_breaks = seq(from =0,to = 5000, by = 500),
silent_NA_warning = TRUE
)
diamond_plot
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.