I am using ggplot to plot Proportional Stacked Bar plot. And the Plot I am getting is something like this:
Borrowing some code from @SimonO101
library(ggplot2)
library(reshape2)
library(RColorBrewer)
mypal <- colorRampPalette( brewer.pal( 9 , "Set1" ) ) #you can try using different palete instead
#of "Set1" until it looks good to you
intercalate <- function(n){ #my crude attempt to shuffle the colors
c(rbind(1:(n/2), n:(n/2+1))) #it will only work for even numbers
}
PropBarPlot<-function(df, mytitle=""){
melteddf<-melt(df, id=names(df)[1], na.rm=T)
ggplot(melteddf, aes_string(x=names(df)[1], y="value", fill="variable")) +
geom_bar(position="fill") +
theme(axis.text.x = element_text(angle=90, vjust=1)) +
labs(title=mytitle)+
scale_fill_manual( values = mypal(8)[intercalate(8)] )
#better would be to calculate the different number of categories
#you have and put that instead of the number 8
}
df <- data.frame(id=letters[1:3],
val0=1:3,
val1=4:6,
val2=7:9,
val3=2:4,
val4=1:3,
val5=4:6,
val6=10:12,
val7=12:14)
print(PropBarPlot(df))
See if that works better for your needs.