Using ggplot2 I want to plot a barplot using colors included in the column of that dataframe
Reproducible example below:
df<-cbind.data.frame("bar_colors"=c("red","blue","green"), "Counts"=c(10,20,30), "Spp"=c("a","a","a"))
ggplot(data=df, aes(x=Spp,y=as.numeric(as.character(Counts)), fill=bar_colors)) +
geom_bar(stat="identity")+scale_fill_manual(values = as.character(df$bar_colors))
But the colors are mixed-up. What do I miss?
Thanks
EDIT: Solved myself by releveling the factor:
df$bar_colors<-factor(df$bar_colors, levels = as.character(df$bar_colors))