I would like to make a stacked histogram in ggplot, where each of the bars (and stacked bars) have a unique colour - using a provided hex value.
For example, take this dataframe.
Pct <- c(0.8026200, 0.1973800, 0.8316421, 0.1683579)
Site <- c("A","A","B", "B")
hex <- c("#53412F", "#B4A383", "#4E3B29", "#B6A37E")
bin <- rep(c(1,2), 2)
df <- as.data.frame(cbind(Site,Pct,hex,bin))
I would like to use the hex colours specified to colour the corresponding bars.
I have tried variations along these lines:
ggplot()+
geom_bar(aes(y=Pct, x=as.character(Site), fill=bin), data=df, stat="identity")+
theme_bw() +
scale_fill_manual("Subject", values=df$hex)
but this produces a green and red colour for each plot?
Any help would be greatly appreciated. Sorry if it is a simple solution - I have not got much experience with stacked barcharts.
Thank you in advance!