I'm working on making plots in R using ggplot2.
My plot looks like this:
values_range
ggplot(subset, aes(x, y, width = 0.5)) +
geom_bar(aes(fill = factor(sort(values))), position = "stack", stat="identity")
where values_range is vector of all possible values and subset is subset of my data
How can I force ggplot to choose colors for fill always in the same way independently from values and subset
Eg. when values_range = [1, 2, 3, 4] and for subset1 values = [1, 2, 3] and for subset2 values = [1, 3, 4]
I want 1, 2, 3, 4 values have the same colour in both subset1 and subset2 plots.
By default it is not in this way, ggplot would give the same colours for 2(1) - 3(2) and 3(1) - 4(2) values
Do you have any idea how can I achieve this?