i made the following plot (I used the "npk" dataset as dummy data because I cannot share the original data - but the systematic of the plot stayed the same):
library(ggplot2)
library(scales)
ggplot(npk,aes(x=block,group=N)) +
geom_bar(aes(y = ..prop..)) +
facet_grid(~ N) +
xlab("blocks") +
scale_y_continuous(labels = percent) +
theme(axis.text.x=element_blank(),axis.ticks.x=element_blank(),
legend.title=element_blank())
block: blocknumber 1-6
N: binary variable 1/0
Now I want to color each bar (= block) in a different color according to the number of the block (I know, this doesn't make much sense here, since the proportion for each block (for variable N) is the same,but with my original data I have different proportions so it makes sense...). In addition to faceting the plot I had to use "group=N" because I needed the proportions per block.
How can I do this? I have tried many different ways to declare the color for these blocks but unfortenately I am not able to color each block, only all blocks together in grey or another specific color...
Thanks for your help! It's very much appreciated! Martina