sjPlot-update: b&w-Figures for Print Journals and Package Vignettes #rstats #dataviz

February 6, 2017

(This article was first published on R – Strenge Jacke!, and kindly contributed to R-bloggers)

My sjPlot-package was just updated on CRAN with some – as I think – useful new features.

First, I have added some vignettes to the package (based on the existing online-documentation) that cover some core features and principles of the sjPlot-package, so you have direct access to these manuals within R. The vignettes are also online on CRAN.

A second feature is the better support for black & white figures. 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()).

sjp.grpfrq(efc$e42dep, efc$c172code, geom.colors = "gs")


Similar to barplots, lineplots can be plotted in greyscale as well (with geom.colors = "gs"). However, in most cases lines colored in greyscale are difficult to distinguish. In this case, certain plot types in sjPlot support black & white figures with different linetypes.

Following plot-types allow black & white figures:

  • sjp.grpfrq(type = „line“)
  • sjp.lm(type = „pred“)
  • sjp.glm(type = „pred“)
  • sjp.lmer(type = „pred“)
  • sjp.glmer(type = „pred“)

Use geom.colors = "bw" to create a b/w-plot.

# 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"))
# print predicted propbabilities
sjp.glm(fit, type = "pred", vars = c("barthel", "sex","dep"), geom.colors = "bw")


Different linetypes do not apply to other linetyped plots (like sjp.lm(type = "eff") or sjp.lm(type = "slope")), because these usually only plot a single line – so there’s no need for different linetypes, you can just set geom.colors = "black" (or geom.colors = "bw").

With this new feature, it’s pretty easy to create plots for (print) journals that require b/w or greyscaled figures.

Tagged: data visualization, ggplot, R, rstats, sjPlot

To leave a comment for the author, please follow the link and comment on their blog: R – Strenge Jacke!. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)