1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
---
title: "Black & White Figures for Print Journals"
author: "Daniel Lüdecke"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Black & White Figures for Print Journals}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r echo = FALSE}
knitr::opts_chunk$set(collapse = TRUE, comment = "#>", dev = "png", fig.width = 7, fig.height = 5, message = FALSE, warning = FALSE)
if (!requireNamespace("sjmisc", quietly = TRUE) ||
!requireNamespace("haven", quietly = TRUE) ||
!requireNamespace("ggplot2", quietly = TRUE) ||
!requireNamespace("sjlabelled", quietly = TRUE)) {
knitr::opts_chunk$set(eval = FALSE)
}
```
This document shows examples how to create b/w figures, e.g. if you don't want colored figures for print-journals.
## Barplots in grey-scaled colors
There are two ways to create plots in black and white or greyscale. For bar plots, `geom.colors = "gs"` creates a plot using a greyscale (based on `scales::grey_pal()`).
```{r}
library(sjPlot)
library(sjmisc)
library(sjlabelled)
library(ggplot2)
theme_set(theme_bw())
data(efc)
plot_grpfrq(efc$e42dep, efc$c172code, geom.colors = "gs")
```
## Lineplots in b/w with different linetypes
Similar to barplots, lineplots - mostly from `plot_model()` - can be plotted in greyscale as well (with `colors = "gs"`). However, in most cases lines colored in greyscale are difficult to distinguish. In this case, `plot_model()` supports black & white figures with different linetypes. Use `colors = "bw"` to create a b/w-plot.
```{r}
# create binrary response
y <- ifelse(efc$neg_c_7 < median(na.omit(efc$neg_c_7)), 0, 1)
# create data frame for fitting model
df <- data.frame(
y = to_factor(y),
sex = to_factor(efc$c161sex),
dep = to_factor(efc$e42dep),
barthel = efc$barthtot,
education = to_factor(efc$c172code)
)
# set variable label for response
set_label(df$y) <- "High Negative Impact"
# fit model
fit <- glm(y ~., data = df, family = binomial(link = "logit"))
# plot marginal effects
plot_model(
fit,
type = "pred",
terms = c("barthel", "sex","dep"),
colors = "bw",
ci.lvl = NA
)
```
Different linetypes do not apply to all linetyped plots, if these usually only plot a single line - so there's no need for different linetypes, and you can just set `colors = "black"` (or `colors = "bw"`).
```{r}
# plot coefficients
plot_model(fit, colors = "black")
```
|