Overall, the following steps can be considered:
Selection of the variable (grouped or not?)
Flipped or not?
Limits/order of the y-axis
Limits/order of the x-axis
Frequencies or percentages?
Labels
Colors and legend
barplotFinal <- ggplot(
pss,
aes(
edu,
fill = edu
)
) +
geom_bar() +
scale_y_continuous(
breaks = seq(
0,
1750,
100
)
) +
scale_x_discrete(
limits = c(
"ES-ISCED I",
"ES-ISCED II",
"ES-ISCED III",
"ES-ISCED IV",
"ES-ISCED V"
)
) +
scale_fill_manual(
name = "Bildungsniveau",
labels = c(
"sehr niedrig",
"niedrig",
"mittel",
"hoch",
"sehr hoch"
),
values = beyonce_palette(25)
) +
geom_text(
stat = "count",
aes(label= ..count..),
vjust = -0.5,
size = 3.5,
color = "darkblue"
) +
labs(
x = "Bildungsniveau",
y = "Häufigkeiten",
title = "My first fancy ggplot ohne NA")
barplotFinal
To save the plot, it is best to use the ggsave()
function. R saves these files in the working directory. If you are unsure where this is, use the getwd()
function. You can change the working directory to any path using setwd()
. Remember: In RStudio Cloud, the working directory is the path of the project you are in! Create a subfolder img
there!
getwd()
ggsave("./img/mffggplot.png",
width = 8,
height = 6,
units = "in",
dpi = 450
)
As a final step with bar charts, we want to group them by another variable!