Overview & Saving

Overall, the following steps can be considered:

  1. Selection of the variable (grouped or not?)

  2. Flipped or not?

  3. Limits/order of the y-axis

  4. Limits/order of the x-axis

  5. Frequencies or percentages?

  6. Labels

  7. 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

Saving Plots

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!