diff --git a/DESCRIPTION b/DESCRIPTION index 646f5c623..ad6cffb06 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: see Title: Model Visualisation Toolbox for 'easystats' and 'ggplot2' -Version: 0.9.0.10 +Version: 0.9.0.11 Authors@R: c(person(given = "Daniel", family = "Lüdecke", diff --git a/R/plot.check_collinearity.R b/R/plot.check_collinearity.R index 4884a65c8..4ba0f36bc 100644 --- a/R/plot.check_collinearity.R +++ b/R/plot.check_collinearity.R @@ -38,14 +38,11 @@ plot.see_check_collinearity <- function(x, dat$group[dat$VIF >= 5 & dat$VIF < 10] <- "moderate" dat$group[dat$VIF >= 10] <- "high" - dat <- datawizard::data_rename( + dat <- datawizard::data_select( dat, - select = c("Term", "VIF", "SE_factor", "Component"), - replacement = c("x", "y", "se", "facet") + select = c(x = "Term", y = "VIF", facet = "Component", group = "group") ) - dat <- datawizard::data_select(dat, select = c("x", "y", "facet", "group")) - if (insight::n_unique(dat$facet) <= 1) { dat$facet <- NULL } diff --git a/tests/testthat/_snaps/plot.check_collinearity/plot-check-collinearity.svg b/tests/testthat/_snaps/plot.check_collinearity/plot-check-collinearity.svg new file mode 100644 index 000000000..59080a3ae --- /dev/null +++ b/tests/testthat/_snaps/plot.check_collinearity/plot-check-collinearity.svg @@ -0,0 +1,80 @@ +<?xml version='1.0' encoding='UTF-8' ?> +<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' class='svglite' data-engine-version='2.0' width='720.00pt' height='576.00pt' viewBox='0 0 720.00 576.00'> +<defs> + <style type='text/css'><![CDATA[ + .svglite line, .svglite polyline, .svglite polygon, .svglite path, .svglite rect, .svglite circle { + fill: none; + stroke: #000000; + stroke-linecap: round; + stroke-linejoin: round; + stroke-miterlimit: 10.00; + } + ]]></style> +</defs> +<rect width='100%' height='100%' style='stroke: none; fill: #FFFFFF;'/> +<defs> + <clipPath id='cpMC4wMHw3MjAuMDB8MC4wMHw1NzYuMDA='> + <rect x='0.00' y='0.00' width='720.00' height='576.00' /> + </clipPath> +</defs> +<g clip-path='url(#cpMC4wMHw3MjAuMDB8MC4wMHw1NzYuMDA=)'> +<rect x='0.000000000000064' y='0.00' width='720.00' height='576.00' style='stroke-width: 0.97; stroke: #FFFFFF; fill: #FFFFFF;' /> +</g> +<defs> + <clipPath id='cpMzQuNTN8NzE1LjAyfDMyLjY2fDU0MC4zMA=='> + <rect x='34.53' y='32.66' width='680.49' height='507.64' /> + </clipPath> +</defs> +<g clip-path='url(#cpMzQuNTN8NzE1LjAyfDMyLjY2fDU0MC4zMA==)'> +<rect x='34.53' y='32.66' width='680.49' height='507.64' style='stroke-width: 0.97; stroke: none; fill: #FFFFFF;' /> +<polyline points='34.53,468.26 715.02,468.26 ' style='stroke-width: 0.97; stroke: #EBEBEB; stroke-linecap: butt;' /> +<polyline points='34.53,354.09 715.02,354.09 ' style='stroke-width: 0.97; stroke: #EBEBEB; stroke-linecap: butt;' /> +<polyline points='34.53,258.87 715.02,258.87 ' style='stroke-width: 0.97; stroke: #EBEBEB; stroke-linecap: butt;' /> +<polyline points='34.53,133.74 715.02,133.74 ' style='stroke-width: 0.97; stroke: #EBEBEB; stroke-linecap: butt;' /> +<polyline points='34.53,540.30 715.02,540.30 ' style='stroke-width: 0.97; stroke: #E5E5E5; stroke-linecap: butt;' /> +<polyline points='34.53,396.23 715.02,396.23 ' style='stroke-width: 0.97; stroke: #E5E5E5; stroke-linecap: butt;' /> +<polyline points='34.53,311.95 715.02,311.95 ' style='stroke-width: 0.97; stroke: #E5E5E5; stroke-linecap: butt;' /> +<polyline points='34.53,205.78 715.02,205.78 ' style='stroke-width: 0.97; stroke: #E5E5E5; stroke-linecap: butt;' /> +<polyline points='34.53,61.71 715.02,61.71 ' style='stroke-width: 0.97; stroke: #E5E5E5; stroke-linecap: butt;' /> +<polyline points='131.74,540.30 131.74,32.66 ' style='stroke-width: 0.97; stroke: #E5E5E5; stroke-linecap: butt;' /> +<polyline points='293.76,540.30 293.76,32.66 ' style='stroke-width: 0.97; stroke: #E5E5E5; stroke-linecap: butt;' /> +<polyline points='455.78,540.30 455.78,32.66 ' style='stroke-width: 0.97; stroke: #E5E5E5; stroke-linecap: butt;' /> +<polyline points='617.81,540.30 617.81,32.66 ' style='stroke-width: 0.97; stroke: #E5E5E5; stroke-linecap: butt;' /> +<rect x='34.53' y='205.78' width='680.49' height='334.52' style='stroke-width: 1.07; stroke: none; stroke-linecap: butt; stroke-linejoin: miter; fill: #3AAF85; fill-opacity: 0.15;' /> +<rect x='34.53' y='61.71' width='680.49' height='144.07' style='stroke-width: 1.07; stroke: none; stroke-linecap: butt; stroke-linejoin: miter; fill: #1B6CA8; fill-opacity: 0.15;' /> +<rect x='34.53' y='32.66' width='680.49' height='29.05' style='stroke-width: 1.07; stroke: none; stroke-linecap: butt; stroke-linejoin: miter; fill: #CD201F; fill-opacity: 0.15;' /> +<line x1='617.81' y1='297.94' x2='617.81' y2='97.67' style='stroke-width: 1.71; stroke: #1B6CA8; stroke-linecap: butt;' /> +<line x1='131.74' y1='284.53' x2='131.74' y2='82.70' style='stroke-width: 1.71; stroke: #1B6CA8; stroke-linecap: butt;' /> +<line x1='455.78' y1='504.72' x2='455.78' y2='348.91' style='stroke-width: 1.71; stroke: #3AAF85; stroke-linecap: butt;' /> +<line x1='293.76' y1='165.06' x2='293.76' y2='32.66' style='stroke-width: 1.71; stroke: #1B6CA8; stroke-linecap: butt;' /> +<line x1='293.76' y1='62.24' x2='293.76' y2='32.66' style='stroke-width: 1.07; stroke: #1B6CA8;' /> +<polygon points='298.97,46.97 293.76,32.66 288.55,46.97 ' style='stroke-width: 1.07; stroke: #1B6CA8; fill: #1B6CA8;' /> +<circle cx='617.81' cy='203.86' r='3.73' style='stroke-width: 0.00; stroke: none; fill: #1B6CA8;' /> +<circle cx='131.74' cy='189.26' r='3.73' style='stroke-width: 0.00; stroke: none; fill: #1B6CA8;' /> +<circle cx='455.78' cy='451.74' r='3.73' style='stroke-width: 0.00; stroke: none; fill: #3AAF85;' /> +<circle cx='293.76' cy='62.24' r='3.73' style='stroke-width: 0.00; stroke: none; fill: #1B6CA8;' /> +</g> +<g clip-path='url(#cpMC4wMHw3MjAuMDB8MC4wMHw1NzYuMDA=)'> +<polyline points='34.53,540.30 34.53,32.66 ' style='stroke-width: 0.97; stroke: #CCCCCC; stroke-linecap: butt;' /> +<text x='30.04' y='543.74' text-anchor='end' style='font-size: 10.00px; fill: #7F7F7F; font-family: sans;' textLength='5.56px' lengthAdjust='spacingAndGlyphs'>1</text> +<text x='30.04' y='399.67' text-anchor='end' style='font-size: 10.00px; fill: #7F7F7F; font-family: sans;' textLength='5.56px' lengthAdjust='spacingAndGlyphs'>2</text> +<text x='30.04' y='315.39' text-anchor='end' style='font-size: 10.00px; fill: #7F7F7F; font-family: sans;' textLength='5.56px' lengthAdjust='spacingAndGlyphs'>3</text> +<text x='30.04' y='209.22' text-anchor='end' style='font-size: 10.00px; fill: #7F7F7F; font-family: sans;' textLength='5.56px' lengthAdjust='spacingAndGlyphs'>5</text> +<text x='30.04' y='65.15' text-anchor='end' style='font-size: 10.00px; fill: #7F7F7F; font-family: sans;' textLength='11.12px' lengthAdjust='spacingAndGlyphs'>10</text> +<polyline points='34.53,540.30 715.02,540.30 ' style='stroke-width: 0.97; stroke: #CCCCCC; stroke-linecap: butt;' /> +<text x='131.74' y='551.66' text-anchor='middle' style='font-size: 10.00px; fill: #7F7F7F; font-family: sans;' textLength='12.23px' lengthAdjust='spacingAndGlyphs'>cyl</text> +<text x='293.76' y='551.66' text-anchor='middle' style='font-size: 10.00px; fill: #7F7F7F; font-family: sans;' textLength='18.35px' lengthAdjust='spacingAndGlyphs'>disp</text> +<text x='455.78' y='551.66' text-anchor='middle' style='font-size: 10.00px; fill: #7F7F7F; font-family: sans;' textLength='20.02px' lengthAdjust='spacingAndGlyphs'>gear</text> +<text x='617.81' y='551.66' text-anchor='middle' style='font-size: 10.00px; fill: #7F7F7F; font-family: sans;' textLength='10.00px' lengthAdjust='spacingAndGlyphs'>wt</text> +<text transform='translate(11.86,286.48) rotate(-90)' text-anchor='middle' style='font-size: 10.00px; fill: #4D4D4D; font-family: sans;' textLength='184.54px' lengthAdjust='spacingAndGlyphs'>Variance Inflation Factor (VIF, log-scaled)</text> +<rect x='293.32' y='558.72' width='162.91' height='17.28' style='stroke-width: 0.97; stroke: none; fill: #FFFFFF;' /> +<line x1='301.96' y1='574.27' x2='301.96' y2='560.45' style='stroke-width: 1.71; stroke: #3AAF85; stroke-linecap: butt;' /> +<circle cx='301.96' cy='567.36' r='3.73' style='stroke-width: 0.00; stroke: none; fill: #3AAF85;' /> +<line x1='371.17' y1='574.27' x2='371.17' y2='560.45' style='stroke-width: 1.71; stroke: #1B6CA8; stroke-linecap: butt;' /> +<circle cx='371.17' cy='567.36' r='3.73' style='stroke-width: 0.00; stroke: none; fill: #1B6CA8;' /> +<text x='315.58' y='570.80' style='font-size: 10.00px; fill: #4D4D4D; font-family: sans;' textLength='41.97px' lengthAdjust='spacingAndGlyphs'>Low (< 5)</text> +<text x='384.79' y='570.80' style='font-size: 10.00px; fill: #4D4D4D; font-family: sans;' textLength='71.44px' lengthAdjust='spacingAndGlyphs'>Moderate (< 10)</text> +<text x='4.98' y='25.60' style='font-size: 10.00px; font-family: sans;' textLength='246.79px' lengthAdjust='spacingAndGlyphs'>High collinearity (VIF) may inflate parameter uncertainty</text> +<text x='4.98' y='13.24' style='font-size: 12.00px; font-family: sans;' textLength='59.36px' lengthAdjust='spacingAndGlyphs'>Collinearity</text> +</g> +</svg> diff --git a/tests/testthat/test-plot.check_collinearity.R b/tests/testthat/test-plot.check_collinearity.R index 4981bc5a2..bfd8903e4 100644 --- a/tests/testthat/test-plot.check_collinearity.R +++ b/tests/testthat/test-plot.check_collinearity.R @@ -1,6 +1,11 @@ test_that("`plot.see_check_collinearity()` works", { m <- lm(mpg ~ wt + cyl + gear + disp, data = mtcars) result <- performance::check_collinearity(m) - expect_s3_class(plot(result), "gg") + + skip_if_not_installed("vdiffr") + vdiffr::expect_doppelganger( + title = "plot.check_collinearity", + fig = plot(result) + ) }) diff --git a/tests/testthat/test-plot.check_dag.R b/tests/testthat/test-plot.check_dag.R index ec39f88b9..5c8658113 100644 --- a/tests/testthat/test-plot.check_dag.R +++ b/tests/testthat/test-plot.check_dag.R @@ -1,5 +1,6 @@ skip_if_not_installed("ggdag") skip_if_not_installed("dagitty") +skip_if_not_installed("vdiffr") test_that("`plot()` for check_dag", { set.seed(1234)