0

I am trying to create 3 plots for categorical vs categorical variables. I am not seeing any legend for different categories of variables C1,C4,C5. Also the bars are greyed out. The dataset has information on 9 categorical variables and 6 numerical variables. C1,C4,C5 has 2,4,3 categories respectively. Hired (1,0) is the variable showing if a candidate will be hired or not.

install.packages("Rmisc")

library(Rmisc)
p1<-ggplot(hireouti, aes(x = Hired, fill = C1)) + geom_bar(position = 'stack', show.legend=TRUE) 
p2<-ggplot(hireouti, aes(x = Hired, fill = C4)) + geom_bar(position = 'stack', show.legend=TRUE)
p3<-ggplot(hireouti, aes(x = Hired, fill = C5)) + geom_bar(position = 'stack', show.legend=TRUE)

multiplot(p1,p2,p3, cols = 3)

The first visualisation below is the output I am getting. I would like to obtain a visualisation like the second one below.

Output with no legend

desired output

I have been able to reproduce the visualisation with legend.

I have executed the code below and C1,C4,C5 were numeric. I have tried converting into factor.

p1<-ggplot(hireouti, aes(x = Hired, fill = factor(C1))) + geom_bar(position = 'stack', show.legend = TRUE) 
p2<-ggplot(hireouti, aes(x = Hired, fill = factor(C4))) + geom_bar(position = 'stack', show.legend = TRUE)
p3<-ggplot(hireouti, aes(x = Hired, fill = factor(C5))) + geom_bar(position = 'stack', show.legend = TRUE)
multiplot(p1,p2,p3, cols = 3) 
K Bh
  • 365
  • 1
  • 4
  • 14
  • 4
    When asking for help, you should include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. It would be helpful to see what `hireouti` contains. – MrFlick May 24 '18 at 13:50
  • I have added information on the variables and the desired output image above. – K Bh May 24 '18 at 14:19
  • We would still need a reproducible dataframe to help us test out solutions on our computers. My first instinct though is that you should really only have one ggplot where fill is = category or something like that – Beeba May 24 '18 at 15:59
  • The issue is *almost certainly* that you are using wide shaped data, but `ggplot` expects long shaped data, so you can map values of a variable to an aesthetic. There are plenty of questions on SO about doing that, but I can't really say more until you post a sample of your data – camille May 26 '18 at 15:56

0 Answers0