Hello. I'm trying to use ggplot to add a legend in one graph.
First, It was with the legend, but he wasn't with the colors I wanted, so I changed the colors, but then the legend just disappeared. I can't put it back, can someone help me?
I used:
ggplot(freqHMatM, aes(fill=freqHMatM$Frequencia, y=Frequencia, x=Genero, label = round(freqHMatM$Frequencia, 4))) +
geom_col(position="fill",
color = "white", show.legend = TRUE, fill = c("mistyrose3", "mistyrose2", "mistyrose1", "mistyrose4", "mistyrose3", "mistyrose2", "mistyrose1")) +
labs(x = NULL, y = "FrequĂȘncia", title = "HMatM") +
theme_classic(base_size = 18) +
scale_y_continuous(labels=percent) +
geom_text(position = position_fill(vjust = 0.5))
And this graph appeared:
(I've never done it, hope that this image is visible)
And, then, I used this one:
ggplot(freqHMatM, aes(fill=freqHMatM$Frequencia, y=Frequencia, x=Genero, label = round(freqHMatM$Frequencia, 4))) +
geom_col(position="fill",
color = "white", show.legend = TRUE, fill = c("mistyrose3", "mistyrose2", "mistyrose1", "mistyrose4", "mistyrose3", "mistyrose2", "mistyrose1")) +
labs(x = NULL, y = "FrequĂȘncia", title = "HMatM") +
theme_classic(base_size = 18) +
scale_y_continuous(labels=percent) +
geom_text(position = position_fill(vjust = 0.5))
And this graph, without legends, appeared:
(Look at the first comment, please, I will put this image there, because new users can put only 1 media)
Well, for the ones who understand it, I clearly don't understand how to use most of these functions. Can anyone just help me to add a legend? And change it's name, if possible?
Just because I think it will probably be important:
HMatM is the answers of a Likert scale, ranging from 1 to 5.
A segregate my data into "man" and "woman", to see if there's any difference in the answers.
"FrequĂȘncia", in my code, is the same as frequency, where I put the frequency of man and woman who answered my questions (it was 57 women and 59 men).
"Genero" is the same as "gender", wich were "man" and "woman".
My "freqHMatM" data looks like this:
(Look at the second comment, please, I will put this image there)
Hope anyone can help me.
Thanks in advance.