0

So this is the following code I used to create a side-by-side bar graph like this:

california %>% 
  pivot_longer(4:6, names_to = "Size", values_to = "Num.Sold") %>% 
  select(-c(AveragePrice)) %>% 
  ggplot(aes(x=region,y=Num.Sold,fill=Size))+
  geom_col(position = "fill")+
  facet_wrap(~type)+
  scale_fill_discrete(breaks=c("Small","Large","Extra Large"))

However, when I plotted the graph, my legend does not show up.

Side-by-side plot

Does anybody know how to remedy this issue? Thanks!

pptaszni
  • 5,591
  • 5
  • 27
  • 43
ngander
  • 11
  • 2
  • Have you try to remove `position = "fill"` in `geom_col()` ? – dc37 Jan 24 '20 at 08:24
  • 2
    Welcome to SO. Please, consider reading this: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example. We would like to help you, but you need to add a piece of your data. I reckon you could simply use `dput()`` – cmirian Jan 24 '20 at 08:25
  • @dc37 I have, but it completely altered the graph, and still doesn't show a legend – ngander Jan 24 '20 at 08:26
  • As pointed it out by @cmirian, you should provide a small example of your data in order we can reproduce the error – dc37 Jan 24 '20 at 08:28
  • 1
    my guess is that your data dose not have "Small","Large","Extra Large" but that is what you like to see on your legend, if that's the case you mixed the `labels` with the `breaks` argument, this should fix it ```scale_fill_discrete(labels=c("Small","Large","Extra Large"), breaks=c())``` – DS_UNI Jan 24 '20 at 10:07
  • @DS_UNI that actually worked, thanks! I will make sure to replicate a sample of my data next time, however – ngander Jan 24 '20 at 17:59

0 Answers0