Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 206305

Aligning Effect Size Plots in R Markdown (using SJplot)

$
0
0

I think part of this question deals with sjPlot package, but I've found the package to be pretty flexible and to mirror ggplot, so I'm hoping someone has the answer.

If you knit the code I've written below (using mtcars) into a pdf, you'll see that the two plots don't align. Set aside that I've willfully created the situation (making y-axes labels different sizes and non-sensical models), but how could I get the two separate plots to be the same size (despite having different length y-axis labels)? Maybe the best I can do is to z-score them and make sure that none of the y-axis labels exceed a certain length (not ideal, but also not horrible).

In addition, I'm also trying to get it so that there would be no (or minimal) vertical empty space in between the two graphs (so that they nearly overlap). So the first thing would be removing the x-axis labels (estimates) and x-axis title and saving them for the last graph (which I've done), but you can still see that this looks JV. How can I do better?

I have about 10 effect size graphs in two columns (one for Math, one for English, plotting PCA results, etc.), but I think the issue can be distilled to the two graphs you'll get from the Markdown.

Thanks much!

---
title: "Untitled"
author: "Effect Sizes"
date: "1/25/2020"
output:
  pdf_document: default

---
```{r echo = FALSE, include=FALSE}

library(tidyverse)
library(lme4)
library(sjPlot)
library(sjlabelled)
```

```{r effect size dem, echo=FALSE, warning=FALSE, message=FALSE, fig.height = 1.1, fig.width = 4, fig.show="hold", fig.align="center"}

mpg <- lmer(mpg~wt + gear + carb + (1|cyl), mtcars, na.action = 'na.exclude', control = lmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), REML = FALSE)

hp <- lmer(mpg~hp + (1|cyl), mtcars, na.action = 'na.exclude', control = lmerControl(optimizer = "nloptwrap", calc.derivs = FALSE), REML = FALSE)

plot_model(mpg, type = "std", title = "")+
  theme(axis.text.x = element_blank(),
         axis.title.x = element_blank())+
  xlab("")+
  ylim(-1,1)


labels <- c(hp = "horse power")
plot_model(hp, type = "std", title = "", axis.labels = labels)+
  xlab("")+
  ylim(-1,1)

```

Viewing all articles
Browse latest Browse all 206305

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>