I would like to add a legend to a ggplot2. The dataframe has many categorical variables that are easily transformable into numbers (they are on a Likert scale). I am trying to display the data with a stat_count().
ggplot(results,aes(as.numeric(results[,x]), fill =results[,x]))+
stat_count(aes(y = stat(count) / sum(count)), show.legend = TRUE)+
geom_text(aes(label = round(stat(count) / sum(count),3), y= stat(count) / sum(count)), stat= "count", vjust = -.25) +
xlim(c(0,5)) +
geom_vline(xintercept = mx, colour = "red", lwd = 2, lty=3) +
labs(title = title) +
xlab(paste0("Your average for this question is: ", mx))+
ylab("")
The ylim needs to be from 0.0 to 1.0.
This is a screenshot of what I would like to achieve, but instead of col I would like to put Legend, I need a color for each number 1 2 3 4 5 although 3, 4 and 5 do not appear. And they to be ordered one under another.