0

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.

aosmith
  • 34,856
  • 9
  • 84
  • 118
  • note that `scale_color_manual` is for colours, but you have `fill=variable` as your aesthetic mapping. – Brian Jun 29 '17 at 14:57
  • Yes, I figured out that this was my mistake. Changing scale_color_manual to scale_fill_manual fixed everything. – user7871651 Jun 29 '17 at 15:16

1 Answers1

0

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.

Mark Peterson
  • 9,370
  • 2
  • 25
  • 48