0
votes

trying to plot a stacked bar plot in ggplot. Having a hard time changing the position of the legend and the color scheme used by the default settings.

I have some data that's been melted into 5 columns called R1, R2, R3, variable, value

stackedCE <- ggplot() + 
geom_bar(data= all_melted, stat = "identity", color = "black", aes(x= R2, 
y= value, fill=variable, width =0.5)) +
ylab("ratio") + 
scale_y_continuous(limits=c(0,100)) +
scale_color_manual(labels=c("Phase 1", "Phase 2"), 
values = c("grey34",  "grey88")) +
xlab("Time (Days)") + 
theme(legend.title = element_blank(), legend.position ="top") +
theme_bw() +
facet_grid(R1 ~ R3, scales="free")

The plot generated works but the colors don't change for the default and the legend title and labels remain the same. Any quick hints would be much appreciated.

1
note that scale_color_manual is for colours, but you have fill=variable as your aesthetic mapping. - Brian
Yes, I figured out that this was my mistake. Changing scale_color_manual to scale_fill_manual fixed everything. - user7871651

1 Answers

0
votes

theme_bw() is resetting all of the theme elements to its defaults after you have manually changed them. Flip the order (put your custom theme() after theme_bw()) and it should work.