Zuerst möchstest du nun die Variable stfdem
darstellen. Überlege dir kurz wie du diese Variable darstellen kannst und versuche selbstständig Code zu schreiben. Schaue erst im Anschluss auf die möglichen Lösungen.
Probier dich aus, bevor du in die anderen Tabs schaust!
barplot <- ggplot(
pss,
aes(stfdem)
) +
geom_bar() +
scale_y_continuous(
breaks = seq(
0,
900,
100
)
) +
scale_x_continuous(
limits = c(
-0.5,
10.5
),
breaks = seq(
0,
10,
1
)
) +
geom_text(
stat = "count",
aes(label= ..count..),
vjust = -0.5,
size = 3.5,
color = "darkblue"
) +
labs(
x = "Zufriedenheit mit der Demkoratie",
y = "Häufigkeiten",
title = "Verteilung von stfdem")
barplot
hist <- ggplot(
pss,
aes(stfdem)
) +
geom_histogram(
aes(y = ..density..),
color = "lightgray",
fill = "gray",
binwidth = 1 # zusätzliches Argument wg pseudo-metrischen Daten
) +
geom_density(
alpha = 0.2,
fill = "lightblue",
bw = 1 # zusätzliches Argument wg pseudo-metrischen Daten (bw = binwidth)
) +
labs(
x = "Zufriedenheit mit Demokratie",
y = "Dichte",
title = "Histogramm stfdem (PSS)"
) +
scale_x_continuous(
breaks = seq(
0,
10,
1
),
limits = c(
-0.5,
10.5
)
)
hist
Super, wenn du das geschafft hast. Jetzt möchtest du noch schauen, ob es Unterschiede auf der Variable nach Geschlecht gibt.
Probier dich aus, bevor du in die anderen Tabs schaust!
stfdemDistrict <- ggplot(
pss,
aes(
stfdem,
fill = district
)
) +
geom_bar(position = position_dodge()) +
scale_y_continuous(
breaks = seq(
0,
200,
10
),
limits = c(
0,
200
)
) +
geom_text(
stat = "count",
aes(label= ..count..),
vjust = -1,
size = 3.5,
position = position_dodge(0.9)
) +
labs(
x = "Zufriedenheit mit Demkoratie",
y = "Häufigkeiten",
title = "Zufriedenheit mit der Demokratie nach Distrikt",
caption = "Data: Panem Social Survey."
) +
scale_fill_manual(
name = "Distrikt",
values = beyonce_palette(26)
) +
facet_grid(~district)
stfdemDistrict
stfdemDistrict2 <- ggplot(
pss,
aes(
stfdem,
fill = district
)
) +
geom_histogram(
aes(y = ..density..),
alpha = 0.5,
binwidth = 1,
position = "identity"
) +
geom_density(
alpha = 0.2,
bw = 1
) +
facet_grid(
.~ district
) +
scale_fill_manual(values = beyonce_palette(72)) +
labs(
x = "Zufriedenheit mit Demkoratie",
y = "Density",
title = "Histogramm von stfdem",
caption = "Data: Panem Social Survey."
) +
theme(legend.position = "none")
stfdemDistrict2
stfdemDistrict3 <- ggplot(
pss,
aes(
stfdem,
district,
fill = district
)
) +
geom_density_ridges(
scale = 0.9,
alpha = 0.4
) +
scale_x_continuous(
limits = c(
0,
10
),
breaks = seq(
0,
10,
1
)
) +
theme_ridges() +
theme(legend.position = "none")
stfdemDistrict3
Weiter geht’s zur Korrelationsdarstellung!