Hi,
How could I change the type of bar plot? From Stacked Bar Charts to Grouped column chart. And let the legend show the pattern of barplot completely(it seems A legend needs).
Thank you for your help in advance.
library(tidyverse)
set.seed(123)
data <- data.frame(
group = rep(c("A", "B"), each = 5),
category = rep(c("cat1", "cat2", "cat3", "cat4", "cat5"), 2),
value = sample(1:10, 10, replace = TRUE)
)
data
ggplot(data, aes(x = category, y = value)) +
geom_bar(position = "dodge", stat = "identity")+
geom_bar_pattern(stat = "identity",
pattern_color = "white",
pattern_fill = "black",
aes(pattern = group))+
scale_fill_manual(values = c("lightblue", "salmon")) +
labs(x = "category", y = "value", fill = "group") +
theme_minimal()
Created on 2023-04-19 with reprex v2.0.2