I want to have a graph with a color scale, however the graph has certain deviations, where the first category is missing and then the color scale does not work any more. Is there a method to skip the first discrete color in a color scale?
I provide an example that does not work below. The first graph has category A in light blue, and the second B. But also in the second B should be dark blue.
I also found this question: How to change default color scheme in ggplot2?
if (!require("pacman")) install.packages("pacman")
pacman::p_load('tidyverse')
first_column <- c("value_1", "value_3", "value_2")
second_column <- c("A", "B", "C", "D", "A", "B", "C", "D")
freq <-c(23, 41, 32, 58, 11, 16, 19, 38)
df2 <- data.frame(first_column, second_column, freq)
ggplot(df2,
aes(x = first_column,
y = freq,
fill = second_column )) +
geom_bar(stat = "identity") +
scale_fill_brewer(palette="Paired")
df3 <-df2
df3$second_column <- ifelse(df3$second_column == "A", "C", df3$second_column)
ggplot(df3,
aes(x = first_column,
y = freq,
fill = second_column )) +
geom_bar(stat = "identity") +
scale_fill_brewer(palette="Paired")