0

I would like to rename my labels (both "Bildungsgrad" and "Bundestagswahl 2021" after having them situated via labeling_list. Currently, they just have there numeric values (see attached picture)Plot I tried both

set_labels=list(Bildungsgrad = c("Anderer Abschluss", "Qualifizierter Hauptschulabschluss", "Mittlere Reife", "Fachabitur/Allgemeines Abitur", "Universitätsabschluss")) and 

vnames <- list(set_varnames = c(StrategischeWahl2021="Strategische Wähler 2021"))
lnames <- list(Bildungsgrad = c("Anderer Abschluss", "Qualifizierter Hauptschulabschluss", "Mittlere Reife", "Fachabitur/Allgemeines Abitur", "Universitätsabschluss"))
labeling_args=vnames, set_labels=lnames

My entire code is here:

Test <- Deskriptive_Statistik

mosaic(~ Bildungsgrad + StrategischeWahl2021, 
       direction = c("v", "h"),
       data = Test,
       shade = TRUE,
       labeling = (labeling_list))
       margins = c(bottom = 5)

Thank you very much ;)

Mr. Draro
  • 77
  • 4
  • Your code is incomplete. The argument `margins=` is outside of the function and is not a valid argument for `mosaic`. The argument `labeling=` is inside the function but the manual page for `mosaic` does not include this argument and you have not defined an object called `labeling_list` your code. Exactly what code did you use to create picture? If you want to use labels instead of numbers, it will be simpler if you just convert the two variables to factors, `?factor`. See the example in the mosaic manual page (`?mosaic`) using the Titanic data set. – dcarlson Aug 15 '22 at 03:17

1 Answers1

0

I now fixed it via a not really elegant solution, but it works. I just renamed the Variable-Name, so now it acts like a legend. Picture

mosaic(data = Test,
   ~Bildungsgrad + StrategischeWahl2021,
   direction = c("v", "h"),
   shade = TRUE,
   labeling_args = list(set_varnames = c(StrategischeWahl2021 = "StrategischeWähler2021", Bildungsgrad = "0=Anderer Abschluss, 1=Qualifizierter Hauptschulabschluss, 2=Mittlere Reife, 3=Fachabitur/Allgemeines Abitur, 4=Universitätsabschluss)"), 
                                 set_labels = list(StrategischeWahl2021 = c("Nein", "Ja")), rep = FALSE),
   gp = shading_hcl, gp_args = list(interpolate = c(1, 1.8)))
Mr. Draro
  • 77
  • 4