0

I'm new to R and I'm trying to plot a small survey where I used a likert-scale.

I'm using

ggplot(Likert, aes(x=Anzahl, y=Frage, fill=Zustimmung)) + geom_col()

to display the data. There are probably better ways to do this and I probably should use data frames as I currently don't use them.

Now the actual Problem: The variable "Zustimung" has 5 different specifications but only 4 of them are shown and there are sorted weirdly. bar chart with likert data

I've found a few different posts online which seem to be regarding this issue but I can't understand them. Could someone please explain why this problem occures and how I can fix this?

wiebke-blip
  • 23
  • 1
  • 4
  • 1
    It will be easier for people to help if you can make your question reproducible. ie provide some sample data and code that produces the issue. I'm guessing you have NAs in one or more of your columns called by ggplot, and that your `Zustimmung` variable is character data (which will always sort alphabetically) when it should probably be a factor, which can be ordered any way you like, such as by using one of the many factor manipulating functions in the `forcats` package. – Jon Spring Jan 04 '23 at 17:36
  • Categories are sorted alphabetically unless you specify otherwise. You can make `Zustimmung` a `factor` class column and specify the order you want, e.g., `Likert$Zustimmung = factor(Likert$Zustimmung, levels = c("tells/teils", "Ich stimme nicht zu", "Ich stimme eher zu", "Ich stimme voll zu"))` (use whatever order you like and make sure to include the missing category). – Gregor Thomas Jan 04 '23 at 17:37
  • And to show all 5 categories in the legend even if they are not present in your data, you can add `scale_fill_discrete(drop = FALSE)` to your plot – Gregor Thomas Jan 04 '23 at 17:39
  • I've closed your question as a duplicate to help as a pointer to existing questions with the same issue. If you run into problems with the solution and need more help, please provide reproducible sample data so we can debug and figure out why the existing answers aren't working. In that case we can re-open your question (or you can ask a new question) as the reproducible example will make any lingering issues clear. – Gregor Thomas Jan 04 '23 at 17:43

0 Answers0