I have the following input data.
sample_data <- data.frame(city = c("a", "b", "c","d", "a", "b", "c", "d"), value = c(10, 11, 17, 12, 13, 14, 11, 8), type = c(1,1,1,1,2,2,2,2), country = c("c1", "c2", "c1", "c1", "c2", "c2", "c1", "c1")) And want to create plots within ggplot that splits the data by type (so two sets of bar charts). I want the order of the bar charts to be grouped by the colours together. So below the right hand chart would group the blue and red bars to be next to each other. I have a large number of variables so manually moving them around would not be an option. The code I used for the charts was:
sample_data <- sample_data %>% mutate(city2 = factor(city, levels=city[order(country)])) ggplot(sample_data) + geom_col(aes(x=city2, y=value, colour=country, fill=country)) + facet_wrap(~type) 

typebycountryin thefacet_wrap()function, do you get what you want?ggplot(sample_data) + geom_col(aes(x=city2, y=value, colour=country, fill=country)) + facet_wrap(~country)