diff --git a/R/check_functions.R b/R/check_functions.R index 9965f8a9..816c0ca5 100644 --- a/R/check_functions.R +++ b/R/check_functions.R @@ -1,6 +1,6 @@ check_facets <- function(dat, facets) { if (!checkmate::test_factor(dat[, facets], ordered = TRUE)) { - message("Facets will be ordered alphabetically. To enforce a custom order, convert your `facet` variable into an ordered factor.") + # message("Facets will be ordered alphabetically. To enforce a custom order, convert your `facet` variable into an ordered factor.") ordered_dat <- dat[order(dat[, facets]), , drop = FALSE] ordered_dat[, facets] <- factor(ordered_dat[, facets], ordered = TRUE diff --git a/R/plot_lineplot.R b/R/plot_lineplot.R index f8e1d75b..79db7a7b 100644 --- a/R/plot_lineplot.R +++ b/R/plot_lineplot.R @@ -49,6 +49,11 @@ plot_lineplot <- function(eatPlot_dat, warning("Split lineplot currently not supported. Set to non-split.") plot_settings$split_plot <- FALSE } + +if(is.null(background_subgroup)){ + message("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.") +} + # Rename/Build needed columns --------------------------------------------- years_list <- prep_years_list(years_lines, years_braces) # plot_dat <- equalize_line_length(plot_dat, plot_settings) diff --git a/tests/testthat/_snaps/vignettes/lineplot-2.svg b/tests/testthat/_snaps/vignettes/lineplot-2.svg index f209ba85..2a00eaf5 100644 --- a/tests/testthat/_snaps/vignettes/lineplot-2.svg +++ b/tests/testthat/_snaps/vignettes/lineplot-2.svg @@ -182,13 +182,13 @@ - - - + + + - + 543 464 523 @@ -222,11 +222,11 @@ - + - - + + 547 @@ -265,12 +265,12 @@ - - - - - - + + + + + + 523 414 525 @@ -305,12 +305,12 @@ - + - - - + + + 500 440 @@ -345,10 +345,10 @@ - + - - + + @@ -387,7 +387,7 @@ - + @@ -428,12 +428,12 @@ - - - - - - + + + + + + 525 457 @@ -469,10 +469,10 @@ - - - - + + + + @@ -511,13 +511,13 @@ - - - - - - - + + + + + + + 527 471 522 @@ -550,14 +550,14 @@ - - - - - - - - + + + + + + + + 537 452 523 @@ -592,13 +592,13 @@ - - - - - - - + + + + + + + 539 449 520 @@ -632,13 +632,13 @@ - - - - - - - + + + + + + + 518 438 @@ -674,14 +674,14 @@ - - - - - - - - + + + + + + + + 516 466 523 @@ -715,14 +715,14 @@ - - - - - - + + + + + + - + 513 435 498 @@ -758,13 +758,13 @@ - - - - - - - + + + + + + + 521 447 527 @@ -800,11 +800,11 @@ - + - - + + 507 diff --git a/tests/testthat/_snaps/vignettes/lineplot-germany-2.svg b/tests/testthat/_snaps/vignettes/lineplot-germany-2.svg deleted file mode 100644 index 5326d499..00000000 --- a/tests/testthat/_snaps/vignettes/lineplot-germany-2.svg +++ /dev/null @@ -1,119 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -533 -454 -522 -412 -522 -412 -492 -349 - - --42 -(6.6) --11 -(3.1) --62 -(7.3) --31 -(4.1) - -2009 -2015 -2015 -2022 -Hören - - - - - - - - - - -533 -454 -522 -412 -522 -412 -492 -349 - - --42 -(6.6) --11 -(3.1) --62 -(7.3) --31 -(4.1) - -2009 -2015 -2015 -2022 -Lesen -lineplot_germany_2 - - diff --git a/tests/testthat/_snaps/vignettes/tableplot-8-4.svg b/tests/testthat/_snaps/vignettes/tableplot-8-4.svg deleted file mode 100644 index e4e136b4..00000000 --- a/tests/testthat/_snaps/vignettes/tableplot-8-4.svg +++ /dev/null @@ -1,1010 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --0.54 --1.48 -0.16 --0.62 --1.16 --1.05 --0.47 -0.37 --0.14 --0.37 --0.25 --0.57 --1.15 -0.07 -0.29 --1.58 --0.80 -(9.6) -(10.9) -(7.8) -(12.1) -(10.2) -(10.1) -(9.5) -(12.3) -(10.2) -(7.5) -(10.7) -(14.8) -(18.0) -(13.4) -(11.9) -(12.7) -(2.6) -55 -26 -42 -47 -30 -28 -49 -44 -47 -43 -59 -38 -47 -47 -37 -45 -35 -45 -59 -72 -26 -40 -40 -48 -37 -30 -57 -38 -53 -30 -46 -43 -42 -40 -45 -47 -55 -43 -37 -23 -38 -29 -37 -35 -28 -35 -34 -54 -24 -35 -45 -Baden­Württemberg -Bayern -Berlin -2 -Brandenburg -Bremen -Hamburg -Hessen -Mecklenburg­Vorpommern -Niedersachsen -Nordrhein­Westfalen -3 -Rheinland­Pfalz -Saarland -Sachsen -Sachsen­Anhalt -Schleswig­Holstein -Thüringen -Deutschland - -2009 - -2015 - -2022 - -Differenz -Schüler:innen -mit -- -Schüler:innen -ohne -Zuwanderungshintergrund -d -(SE) -Δ -M -Δ -M -Δ -M -Land - - - - - - - - - -0 -10 -20 -30 -40 -50 -60 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(44.1) -(36.9) -(22.7) -(19.8) -(29.2) -(39.1) -(44.6) -(38.5) -(38.4) -(44.5) -(37.8) -(51.7) -(21.6) -(51.0) -(42.3) -(29.1) -(39.9) -44 -37 -23 -20 -29 -39 -45 -38 -38 -45 -38 -52 -22 -51 -42 -29 -40 - -2015 -- -2009 - -Veränderung -der -Differenz -(SE) -Δ -M -2015 -- -Δ -M -2009 - - - - - - - - - -0 -10 -20 -30 -40 -50 -60 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(50.0) -(53.6) -(42.7) -(34.6) -(43.7) -(31.3) -(42.9) -(36.5) -(53.1) -(32.3) -(55.1) -(54.4) -(51.7) -(31.6) -(35.0) -(36.8) -(41.9) -50 -54 -43 -35 -44 -31 -43 -37 -53 -32 -55 -54 -52 -32 -35 -37 -42 - -2022 -- -2015 - -Veränderung -der -Differenz -(SE) -Δ -M -2015 -- -Δ -M -2009 - - - - - - - - - -0 -10 -20 -30 -40 -50 -60 -tableplot_8.4 - - diff --git a/tests/testthat/_snaps/vignettes/tableplot-trend.svg b/tests/testthat/_snaps/vignettes/tableplot-trend.svg deleted file mode 100644 index 99e7c258..00000000 --- a/tests/testthat/_snaps/vignettes/tableplot-trend.svg +++ /dev/null @@ -1,1136 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -5 -11 -4 -10 -5 -9 -4 -15 -7 -14 -5 -9 -5 -9 -5 -19 -5 -13 -4 -9 -5 -11 -6 -21 -5 -19 -5 -20 -5 -13 -5 -21 -3 -5 --20 --22 --14 --30 -2 --18 -13 -17 --11 --6 -4 -16 --5 --20 --9 --20 --5 --1 --15 --25 --19 --5 -6 --12 -7 -30 --15 --8 -6 -11 -0 --21 --11 --18 -96 -103 -87 -90 -97 -105 -96 -107 -97 -98 -93 -98 -92 -95 -90 -98 -81 -85 -92 -94 -89 -90 -90 -96 -91 -97 -98 -108 -86 -89 -93 -99 -91 -96 -523 -485 -532 -496 -525 -472 -513 -497 -502 -480 -547 -523 -520 -473 -505 -494 -522 -497 -523 -479 -520 -490 -524 -515 -523 -520 -498 -492 -527 -515 -506 -477 -522 -488 -83 -88 -78 -83 -88 -89 -89 -86 -92 -85 -80 -87 -75 -78 -84 -90 -85 -92 -76 -83 -85 -83 -94 -91 -85 -90 -86 -87 -84 -78 -79 -88 -82 -86 -543 -508 -547 -526 -523 -490 -500 -481 -513 -486 -543 -508 -525 -493 -513 -514 -527 -498 -537 -505 -539 -495 -518 -527 -516 -490 -513 -499 -521 -504 -507 -499 -533 -505 -aohneZWH -einET -aohneZWH -einET -aohneZWH -einET -aohneZWH -einET -aohneZWH -einET -aohneZWH -einET -aohneZWH -einET -aohneZWH -einET -aohneZWH -einET -aohneZWH -einET -aohneZWH -einET -aohneZWH -einET -aohneZWH -einET -aohneZWH -einET -aohneZWH -einET -aohneZWH -einET -aohneZWH -einET -Baden­Wuerttemberg -Bayern -Berlin -Brandenburg -Bremen -Hamburg -Hessen -Mecklenburg­Vorpommern -Niedersachsen -Nordrhein­Westfalen -Rheinland­Pfalz -Saarland -Sachsen -Sachsen­Anhalt -Schleswig­Holstein -Thueringen -total - -2009 -a - -2015 -a - -Differenz -2015-2009 -a -d -(SE) -M -2015 -- -M -2009 -SD -M -SD -Δ -M -Land - - - - - - - - - - - -0 --10 --20 --30 --40 -10 -20 -30 -40 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -0 -0 -0 -0 -0 -0 --1 -0 -0 -0 -0 -0 -0 -0 -0 --1 -0 --1 -0 -0 -0 -0 -0 -0 -0 -0 -0 --1 -0 --1 -0 -0 -0 -0 -(4.9) -(11.1) -(4.4) -(10.3) -(5.2) -(9.2) -(4.4) -(14.7) -(6.8) -(13.8) -(5.3) -(9.2) -(4.7) -(8.5) -(4.6) -(19.2) -(4.9) -(12.8) -(4.5) -(9.2) -(4.8) -(11.3) -(6.2) -(20.7) -(5.0) -(18.9) -(4.7) -(20.0) -(4.8) -(13.5) -(4.8) -(20.8) -(3.1) -(4.8) --16 --41 --31 --8 --38 --45 --55 --39 --29 --41 --7 --31 --31 --9 --39 --48 --28 --56 --29 --44 --32 --17 --37 --12 --32 --49 --28 --51 --43 --58 --38 --35 --31 --34 -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -112 -117 -99 -103 -114 -115 -102 -106 -113 -115 -96 -98 -105 -99 -97 -93 -95 -102 -104 -103 -104 -97 -107 -111 -103 -108 -101 -94 -110 -118 -96 -106 -104 -108 -507 -445 -501 -488 -487 -428 -458 -458 -472 -439 -540 -492 -489 -464 -466 -446 -494 -441 -494 -435 -488 -474 -487 -503 -491 -470 -470 -440 -485 -458 -468 -443 -492 -454 -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -96 -103 -87 -90 -97 -105 -96 -107 -97 -98 -93 -98 -92 -95 -90 -98 -81 -85 -92 -94 -89 -90 -90 -96 -91 -97 -98 -108 -86 -89 -93 -99 -91 -96 -523 -485 -532 -496 -525 -472 -513 -497 -502 -480 -547 -523 -520 -473 -505 -494 -522 -497 -523 -479 -520 -490 -524 -515 -523 -520 -498 -492 -527 -515 -506 -477 -522 -488 -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b -b - -2015 - -2022 - -Differenz -2022-2015 -d -(SE) -M -2022 -- -M -2015 -SD -M -SD -M - - - - - - - - - - - - - - - -0 --10 --20 --30 --40 --50 --60 -10 -20 -30 -40 -50 -60 -tableplot_trend - - diff --git a/tests/testthat/test-vignettes.R b/tests/testthat/test-vignettes.R index e2676200..6239acc3 100644 --- a/tests/testthat/test-vignettes.R +++ b/tests/testthat/test-vignettes.R @@ -7,7 +7,7 @@ test_that("lineplot with two groups works", { }) test_that("lineplot of Germany with two groups works", { - vdiffr::expect_doppelganger("lineplot_germany_2", lineplot_germany_2) + # vdiffr::expect_doppelganger("lineplot_germany_2", lineplot_germany_2) }) test_that("lineplot with one group works", { @@ -17,7 +17,7 @@ test_that("lineplot with one group works", { test_that("tableplot for trend works", { - vdiffr::expect_doppelganger("tableplot_trend", tableplot_trend) + # vdiffr::expect_doppelganger("tableplot_trend", tableplot_trend) }) test_that("tableplot 6.5 works", { @@ -29,5 +29,5 @@ test_that("tableplot 6.6 works", { }) test_that("tableplot 8.4 works", { - vdiffr::expect_doppelganger("tableplot_8.4", tableplot_8.4) + # vdiffr::expect_doppelganger("tableplot_8.4", tableplot_8.4) }) diff --git a/vignettes/lineplots.Rmd b/vignettes/lineplots.Rmd index 90a53e0a..37e19f43 100644 --- a/vignettes/lineplots.Rmd +++ b/vignettes/lineplots.Rmd @@ -65,67 +65,70 @@ dat_lineplot_2 <- prep_lineplot( trend_mw, subgroup_var = "geschlecht" ) +dat_lineplot_2 <- process_bundesland(dat_lineplot_2) -dat_lineplot_2$TR_BUNDESLAND <- gsub("ue", "ü", dat_lineplot_2$TR_BUNDESLAND) -``` - - -```{r} lineplot_2 <- plot_lineplot( dat_lineplot_2, - point_sig = "sig_comparison_crossDiffTotal_subgroupTotal", 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(split_plot = FALSE, default_list = lineplot_4x4) + plot_settings = plotsettings_lineplot(default_list = lineplot_4x4) ) - -## Jetzt wird Background line irgendwo nicht rausgefiltert. ``` -```{r save lineplot_2} +```{r} #| eval: false save_plot(lineplot_2, filename = "C:/Users/hafiznij/Downloads/lineplot_2_groups.pdf") ``` -## Lineplot for whole Germany + -```{r lineplot_germany} -trend_ger <- prep_lineplot( - trend_mw, - subgroup_var = "geschlecht" -) + -trend_ger_lesen <- trend_ger -trend_ger_lesen$kb <- "Lesen" + + + + -trend_total <- rbind(trend_ger, trend_ger_lesen) -trend_total$kb <- gsub("hoeren", "Hören", trend_total$kb) + -trend_total <- subset(trend_total, TR_BUNDESLAND == "total") |> - subset(geschlecht %in% c("m", "w")) + + -trend_total$TR_BUNDESLAND <- gsub("ue", "ü", trend_total$TR_BUNDESLAND) -``` + + -```{r} -lineplot_germany_2 <- plot_lineplot(trend_total, - years_lines = list(c(2009, 2015), c(2015, 2022)), - years_braces = list(c(2009, 2015), c(2015, 2022)), - facet_var = "kb", - title_superscripts = NULL, - plot_settings = plotsettings_lineplot( - brace_label_nudge_x = 0.3, - split_plot = FALSE, - background_lines = FALSE, - default_list = lineplot_4x4 - ) -) -``` + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -```{r save lineplot_germany_2_groups} -#| eval: false -save_plot(lineplot_germany_2, filename = "C:/Users/hafiznij/Downloads/lineplot_deutschland.pdf", height = 226.2 / 4) -``` diff --git a/vignettes/tableplots.Rmd b/vignettes/tableplots.Rmd index 65c4aeb2..77075011 100644 --- a/vignettes/tableplots.Rmd +++ b/vignettes/tableplots.Rmd @@ -18,7 +18,7 @@ library(eatPlot) # Geschlechterkapitel ## Abbildung 6.5 -Now we have to filter the data in such a way, that it looks like the table we want to plot. +First we prepare the data: ```{r} mw_prepped <- prep_tablebarplot(trend_mw, @@ -53,8 +53,6 @@ mw_prepped <- rbind(mw_prepped_lesen, mw_prepped_hören) ``` - - Now we can easily plot the barplot, after sorting the data.frame and adding a y-axis: ```{r} @@ -275,403 +273,403 @@ tableplot_6.6 ``` -# Zuwanderungskapitel -```{r} -zwh_prepped <- prep_tablebarplot(trend_zwh, - subgroup_var = "zwh", - comparisons = c("groupDiff", "trend_groupDiff") -) -zwh_prepped <- zwh_prepped[order(zwh_prepped$TR_BUNDESLAND), ] -zwh_prepped$TR_BUNDESLAND <- gsub("total", "Deutschland", zwh_prepped$TR_BUNDESLAND) - -zwh_prepped$TR_BUNDESLAND <- gsub("ue", "ü", zwh_prepped$TR_BUNDESLAND) -zwh_prepped$TR_BUNDESLAND <- gsub("Berlin", "Berlin2", zwh_prepped$TR_BUNDESLAND) -zwh_prepped$TR_BUNDESLAND <- gsub("Nordrhein-Westfalen", "Nordrhein-Westfalen3", zwh_prepped$TR_BUNDESLAND) - -## I add an empty column for being able to easily adjust the sapce between subplots: -zwh_prepped$empty <- NA -``` - - -```{r} -column_widths_stand <- standardize_column_width( - column_widths = list( - p1 = c(0.1, rep(0.035, 5), NA), - p2 = c(0.025, 0.05, 0.035, NA), - p3 = c(0.05, 0.035, NA) - ), - plot_ranges = c(65, 65, 65) # Range of the x-axes of both plots set in 'axis_x_lims'. -) -``` - -```{r} -p_1 <- plot_tablebarplot( - dat = zwh_prepped, - bar_est = "est_2022_groupDiff_mean", - bar_sig = "sig_2022_groupDiff_mean", - column_spanners = list( - "**2009**" = c(2), - "**2015**" = c(3), - "**2022**" = c(4, 7) - ), - column_spanners_2 = list( - "**Differenz Schüler:innen mit - Schüler:innen ohne
Zuwanderungshintergrund**" = c(2, 7) - ), - columns_table_se = list(NULL, NULL, NULL, NULL, "se_2022_groupDiff_mean", NULL), - headers = list( - "Land", - "\u0394 *M*", - "\u0394 *M*", - "\u0394 *M*", - "*(SE)*", - "*d*", - " " - ), - columns_table = c( - "TR_BUNDESLAND", - "est_2009_groupDiff_mean", - "est_2015_groupDiff_mean", - "est_2022_groupDiff_mean", - "se_2022_groupDiff_mean", - "es_2022_groupDiff_mean" - ), - columns_table_sig_bold = list( - NULL, - "sig_2009_groupDiff_mean", - "sig_2015_groupDiff_mean", - "sig_2022_groupDiff_mean", - NULL, - "sig_2022_groupDiff_mean" - ), - y_axis = "y_axis", - columns_round = c(0, 0, 0, 0, 0, 2), - plot_settings = plotsettings_tablebarplot( - column_spanners_2_row_height = 2, - axis_x_lims = c(0, 65), - bar_pattern_spacing = 0.0249, - background_stripes_colour = c(rep(c("white", "#EBFDF3"), 8), "grey"), - # bar_fill_colour = c("#20D479", "#8DEBBC"), - bar_background_lines = "scale_breaks", - columns_alignment = c(0, 0.5, 0.5, 0.5, 2, 0.5), - columns_width = column_widths_stand$p1, - headers_row_height = 1.5, - default_list = barplot_table_plot_pattern - ) -) -``` - -```{r} -p_2 <- plot_tablebarplot( - dat = zwh_prepped, - bar_est = "est_2015 - 2009_trend_groupDiff_mean", - bar_sig = "sig_2015 - 2009_trend_groupDiff_mean", - column_spanners = list( - "**2015 - 2009**" = c(2, 4) - ), - column_spanners_2 = list( - "**Veränderung der Differenz
**" = c(2, 4) - ), - columns_table_se = list(NULL, NULL, "est_2015 - 2009_trend_groupDiff_mean"), - headers = list( - " ", - "\u0394 *M*2015 -
\u0394 *M*2009", - "*(SE)*", - " " - ), - columns_table = c( - "empty", - "est_2015 - 2009_trend_groupDiff_mean", - "se_2015 - 2009_trend_groupDiff_mean" - ), - columns_table_sig_bold = list( - NULL, "sig_2015 - 2009_trend_groupDiff_mean", NULL - ), - y_axis = "y_axis", - plot_settings = plotsettings_tablebarplot( - column_spanners_2_row_height = 2, - axis_x_lims = c(0, 65), - bar_pattern_spacing = 0.0375, - background_stripes_colour = c(rep(c("white", "#EBFDF3"), 8), "grey"), - bar_background_lines = "scale_breaks", - columns_alignment = c(0.5, 0.5, 2), - headers_alignment = c(0, 0, 2, 0), - headers_nudge_x = c(0, 4, 0, 0), - columns_width = column_widths_stand$p2, - headers_row_height = 1.5, - default_list = barplot_table_plot_pattern - ) -) -``` - -```{r} -p_3 <- plot_tablebarplot( - dat = zwh_prepped, - bar_est = "est_2022 - 2015_trend_groupDiff_mean", - bar_sig = "sig_2022 - 2015_trend_groupDiff_mean", - column_spanners = list( - "**2022 - 2015**" = c(1, 3) - ), - column_spanners_2 = list( - "**Veränderung der Differenz
**" = c(1, 3) - ), - columns_table_se = list(NULL, "est_2022 - 2015_trend_groupDiff_mean"), - headers = list( - "\u0394 *M*2015 -
\u0394 *M*2009", - "*(SE)*", - " " - ), - columns_table = c( - "est_2022 - 2015_trend_groupDiff_mean", - "se_2022 - 2015_trend_groupDiff_mean" - ), - columns_table_sig_bold = list( - "sig_2022 - 2015_trend_groupDiff_mean", NULL - ), - y_axis = "y_axis", - plot_settings = plotsettings_tablebarplot( - bar_pattern_spacing = 0.0375, - column_spanners_2_row_height = 2, - axis_x_lims = c(0, 65), - background_stripes_colour = c(rep(c("white", "#EBFDF3"), 8), "grey"), - bar_background_lines = "scale_breaks", - columns_alignment = c(0.5, 2), - headers_alignment = c(0, 2, 0), - headers_nudge_x = c(4, 0, 0), - columns_width = column_widths_stand$p3, - headers_row_height = 1.5, - default_list = barplot_table_plot_pattern - ) -) -``` - -```{r} -bar_pattern_spacing_stand <- standardize_pattern_spacing(list(p_1, p_2, p_3), pattern_spacing = 0.05) -``` - - -```{r} -tableplot_8.4 <- combine_plots(list(p_1, p_2, p_3)) -``` - -```{r} -#| eval: false -save_plot(tableplot_8.4, filename = "C:/Users/hafiznij/Downloads/abb_8.4_greek_cmyk.pdf", width = 320, height = 226.2 / 2, encoding = "Greek.enc") - - -ggplot2::ggsave( - filename = "C:/Users/hafiznij/Downloads/abb_8.4_greek.pdf", tableplot_8.4, - width = 320, height = 226.2 / 2, units = "mm", - device = cairo_pdf -) - -## Okay, so either the letters are not rendered corretly, or the color model is wrong. -``` - - -# Trend Lesen Deutsch -```{r} -library(eatPlot) -``` - -In a first step, the data has to be prepared: - -```{r} -dat_prepped <- prep_tablebarplot( - trend_3, - subgroup_var = "mhg", - par = c("mean", "sd"), - facet_var = "TR_BUNDESLAND", - total_facet = "total", - comparisons = c("none", "trend") -) -``` - -This results in a large dataframe, containing a column for each comparisons made in the data: - -```{r} -#| eval: false -str(dat_prepped) -``` - -The columns are all named after the same scheme: - -1. First, the column type is shown: `est_` for example contains estimated values, while `sig_` gives us information about the significance, `es_` about the effect size and `se_` about the standard errors of the estimates. -1. This is followed by the year(s) the value is referring to. -If it is refering to a trend, this is indicated like so: `2015 - 2009`. -1. Then we can see the type of comparison the values in the column are referring to. -For example, `none` means that no comparison was made, while `trend` indicates that a trend was calculated. -`crossDiff` shows us a crossDiff and `crossDiffTotal` a crossDiff between some subgroup and an overarching total group (like a state vs. the whole of Germany). -See [] for a more thorough description of the different comparsions available in `eatRep`. - -I'd suggest to reduce the `data.frame` by selecting the columns needed for the plot in the next step. -This makes it easier to spot problems in the data. -For example, I might have gathered either from the data directly, or from a template, that I will need the following columns: - -```{r} -table_dat <- dat_prepped[, c( - "TR_BUNDESLAND", - "mhg", - "est_2009_none_mean", - "est_2009_none_sd", - "est_2015_none_mean", - "est_2015_none_sd", - "est_2015 - 2009_trend_mean", - "sig_2015 - 2009_trend_mean", - "se_2015 - 2009_trend_mean", - "es_2015 - 2009_trend_mean" -)] -``` - - - - - - -```{r} -dat_prepped <- subset(dat_prepped, mhg %in% c("aohneZWH", "einET") & grep("- total", dat_prepped$TR_BUNDESLAND, invert = TRUE)) - - -dat_prepped <- dat_prepped[order(dat_prepped$TR_BUNDESLAND), ] - -dat_prepped$TR_BUNDESLAND[duplicated(dat_prepped$TR_BUNDESLAND)] <- " " - -column_widths_stand <- standardize_column_width( - column_widths = list( - p1 = c(0.1, 0.05, rep(0.05, 7), NA), - p2 = c(rep(0.05, 7), NA) - ), - plot_ranges = c(80, 120) # Range of the x-axes of both plots set in 'axis_x_lims'. -) - -p_1 <- plot_tablebarplot( - dat = dat_prepped, - bar_est = "est_2015 - 2009_trend_mean", - bar_label = NULL, - bar_sig = "sig_2015 - 2009_trend_mean", - bar_fill = "mhg", - column_spanners = list( - "**2009**a" = c(3, 4), - "**2015**a" = c(5, 6), - "**Differenz 2015-2009a**" = c(7, 10) - ), - headers = list( - "**Land**", - " ", - "\u0394 *M*", - "*SD*", - "*M*", - "*SD*", - "M2015 - M2009", - "*(SE)*", - "*d*", - " " - ), - columns_table = c( - "TR_BUNDESLAND", - "mhg", - "est_2009_none_mean", - "est_2009_none_sd", - "est_2015_none_mean", - "est_2015_none_sd", - "est_2015 - 2009_trend_mean", - "se_2015 - 2009_trend_mean", - "es_2015 - 2009_trend_mean" - ), - columns_table_sig_bold = list( - NULL, - NULL, - "sig_2009_none_mean", - NULL, "sig_2015_none_mean", - NULL, - "sig_2015 - 2009_trend_mean", - NULL, - NULL - ), - y_axis = "y_axis", - plot_settings = plotsettings_tablebarplot( - axis_x_lims = c(-40, 40), - background_stripes_colour = c(rep(c("white", "white", "#EBFDF3", "#EBFDF3"), 8), "grey", "grey"), - bar_fill_colour = c("#20D479", "#8DEBBC"), - columns_alignment = c(0, 0, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5), - columns_width = column_widths_stand$p1, - headers_alignment = c(0, 0, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0), - default_list = barplot_table_plot_pattern - ) -) - -p_2 <- plot_tablebarplot( - dat = dat_prepped, - bar_est = "est_2022 - 2015_trend_mean", - bar_label = NULL, - bar_sig = "sig_2022 - 2015_trend_mean", - bar_fill = "mhg", - column_spanners = list( - "**2015**" = c(1, 2), - "**2022**" = c(3, 4), - "**Differenz 2022-2015**" = c(5, 8) - ), - headers = list( - "*M*", - "*SD*", - "*M*", - "*SD*", - "M2022 - M2015", - "*(SE)*", - "*d*", - " " - ), - columns_table = c( - "est_2015_none_mean", - "est_2015_none_sd", - "est_2022_none_mean", - "est_2022_none_sd", - "est_2022 - 2015_trend_mean", - "se_2022 - 2015_trend_mean", - "es_2022 - 2015_trend_mean" - ), - columns_table_se = list(NULL, NULL, NULL, NULL, NULL, "se_2015 - 2009_trend_mean", NULL), - columns_table_sig_bold = list( - "sig_2015_none_mean", - NULL, - "sig_2022_none_mean", - NULL, - "sig_2022 - 2015_trend_mean", - NULL, - NULL - ), - columns_table_sig_superscript = list( - "sig_2015_none_mean", - NULL, - "sig_2022_none_mean", - NULL, - "sig_2022 - 2015_trend_mean", - NULL, - NULL - ), - y_axis = "y_axis", - plot_settings = plotsettings_tablebarplot( - axis_x_lims = c(-60, 60), - background_stripes_colour = c(rep(c("white", "white", "#EBFDF3", "#EBFDF3"), 8), "grey", "grey"), - bar_fill_colour = c("#20D479", "#8DEBBC"), - columns_alignment = c(0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5), - columns_width = column_widths_stand$p2, - headers_alignment = c(0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0), - default_list = barplot_table_plot_pattern - ) -) - -tableplot_trend <- combine_plots(list(p_1, p_2)) - -# save_plot(example_plot, filename = "/home/nick/Downloads/test_table.pdf", width = 320) -``` - -```{r} -#| eval: false -save_plot(tableplot_trend, - filename = "C:/Users/hafiznij/Downloads/test_table_greek.pdf", width = 320, - encoding = "Greek.enc" -) -``` + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +