Achsenformatierung
Titel der x- und y-Achse ändern
Die Titel der x- und y-Achse werden von ggplot automatisch erstellt. Dabei wird der zugewiesene Ausdruck verwendet, was oft unschön wirkt und wenig aussagekräftig ist. Betrachtet dazu das Beispiel unten, in dem wir die Gesamtemissionen für jedes Lebensmittelprodukt aus dem Datensatz Environmental Impacts of Food Production als Balkendiagramm darstellen:
food_production %>%
filter(total_emissions > 5) %>%
ggplot() +
aes(x = total_emissions, y = reorder(food_product, total_emissions)) +
geom_col()

Um die Beschriftungen zu verbessern, können wir mit den Funktionen xlab()
und ylab()
aussagekräftigere Titel vergeben:
food_production %>%
filter(total_emissions > 5) %>%
ggplot() +
aes(x = total_emissions, y = reorder(food_product, total_emissions)) +
geom_col() +
xlab("Total Emissions") +
ylab("Food Product")
Das Ergebnis sieht schon gleich viel besser aus:

Die Achsenbeschriftungen können wir auch über die etwas generischere Funktion labs()
erreichen:
food_production %>%
filter(total_emissions > 5) %>%
ggplot() +
aes(x = total_emissions, y = reorder(food_product, total_emissions)) +
geom_col() +
labs(x = "Total Emissions", y = "Food Product")
Formatierung der Achsenbeschriftung
Quellen
Last updated
Was this helpful?