Skip to contents

This vignette shows you how to plot lineplots from eatRep data. The workflow is optimized for Bildungstrend-graphs, but can be expanded for plotting other eatRep data as well.

Lineplot for one group

Let’s take example data from the trend_mw example dataset. The first step in the workflow always is the data preparation. This is needed to bring the eatRep data into the correct format for plotting.

dat_lineplot_1 <- prep_lineplot(
  trend_mw,
  subgroup_var = "geschlecht" ## Leave this argument if you have only one subgroup
)

It might be necessary to do some slight manual data preparation:

## Don't do that if you only have one group in your data, or want to plot all groups
dat_lineplot_1 <- subset(dat_lineplot_1, subgroup_var == "total")

## For correctly displaying the state names:
dat_lineplot_1 <- process_bundesland(dat_lineplot_1)

And then we can already plot:

lineplot_1 <- plot_lineplot(dat_lineplot_1,
  years_lines = list(c(2009, 2015), c(2015, 2022)),
  years_braces = list(c(2009, 2015), c(2015, 2022)),
  plot_settings = plotsettings_lineplot(default_list = lineplot_4x4)
)
## You haven't set a background_subgroup. This might lead to unexpected behaviour, if actually one group should be plotted in the background. Most times this will be the 'total' group.
save_plot(lineplot_1, filename = "C:/Users/hafiznij/Downloads/lineplot_1_group.pdf")

Lineplot for two groups

dat_lineplot_2 <- prep_lineplot(
  trend_mw,
  subgroup_var = "geschlecht"
)
dat_lineplot_2 <- process_bundesland(dat_lineplot_2)


## We can set the order of the brace labels by setting the factor levels of the subgroup_var:
dat_lineplot_2$subgroup_var <- factor(dat_lineplot_2$subgroup_var, levels = c("w", "m", "total"), ordered = TRUE)

lineplot_2 <- plot_lineplot(
  dat_lineplot_2,
  years_lines = list(c(2009, 2015), c(2015, 2022)),
  years_braces = list(c(2009, 2015), c(2015, 2022)),
  background_subgroup = "total",
  plot_settings = plotsettings_lineplot(subgroup_colours = c(w = "#000000", m = "#999999"), ## Here we determine the colours of the subgroups
                                        default_list = lineplot_4x4)
)
save_plot(lineplot_2, filename = "C:/Users/hafiznij/Downloads/lineplot_2_groups.pdf")
lineplot_2