Skip to content

raeslab/loreplotr

Repository files navigation

R-CMD-check License: CC BY-NC-SA 4.0

LoreplotR - Logistic Regression Plots in R

LoreplotR is an R package to draw Logistic Regression plots, which compare the prevalence of different categories with a specific feature. This type of visualization was used in Vieira-Silva et al. Statin therapy is associated with lower prevalence of gut microbiota dysbiosis to show that the frequency of a specific gut composition, aka. an enterotype, increases along with an increasing Body Mass Index.

If you prefer a Python implementation, have a look at lorepy

Setup

LoreplotR needs to be installed directly from GitHub using devtools. From an R console enter the commands below.

library(devtools)
install_github("raeslab/loreplotr")

If you are using renv, instead use the commands below to install this package.

renv::install("raeslab/loreplotr")

Usage

LoreplotR needs to be passed a dataframe, the (numerical) feature to plot on the x-axis and the (categorical) feature for the y-axis. There is one optional parameter draw_dots which allows you to show/hide dots indicating where individual samples included in the dataframe are located in the plot. The package will return a ggplot2 plot which can be saved/changed using functions from that library.

Example

Below is an example that shows data from the mtcars dataset and highlights how the proportions of cars with a different number of cylinders changes in function of fuel efficiency (here included as mile per gallon, mpg).

library(dplyr)
library(loreplotr)

data("mtcars")

mtcars$cyl <- paste("cyl", mtcars$cyl, sep="_")

t <- mtcars %>% loreplotr("mpg", "cyl", draw_dots=TRUE)
t

Example loreplot using mtcars dataset

As LoreplotR is built upon ggplot2, customization is possible using functions from the ggplot2 package. E.g. using the function scale_fill_manual a custom color palette can be selected.

library(dplyr)
library(loreplotr)
library(ggplot2)

data("mtcars")

mtcars$cyl <- paste("cyl", mtcars$cyl, sep="_")

t <- mtcars %>% loreplotr("mpg", "cyl")

t <- t + scale_fill_manual(values = c("#DC9362", "#6BE19F", "#A373E5"))
t

Example loreplot using mtcars dataset and custom colors

To change the appearance of the dots, loreplotr exposes the size, shape, fill, colour and alpha parameters through dots_size, dots_shape,dots_fill,dots_colour and,dots_alpha respectively.

library(dplyr)
library(ggplot2)
library(loreplotr)

data("mtcars")

mtcars$cyl <- paste("cyl", mtcars$cyl, sep="_")

t <- mtcars %>% loreplotr("mpg", "cyl", dots_colour="black", dots_size=2, dots_alpha = 1, dots_shape=3)
t

t <- t + scale_fill_manual(values = c("#DC9362", "#6BE19F", "#A373E5"))
t

Example loreplot using mtcars dataset and custom dots

Troubleshooting/FAQ

  • Why do my category labels change, with spaces replaced by dots and numbers preceded by an 'X'? This occurs because R imposes specific rules on valid column names. Invalid characters in column names are replaced with dots, and numbers at the start are prefixed with 'X'. This is detailed in the make.names function. Since loreplotr includes a step that necessitates creating a dataframe with a column for each group, label modifications occur. It's best to use valid labels whenever possible. If not feasible, consider using ggplot2's scale_fill_discrete or scale_fill_manual to adjust legend labels.

Contributing

Any contributions you make are greatly appreciated.

  • Found a bug or have some suggestions? Open an issue.
  • Pull requests are welcome! Though open an issue first to discuss which features/changes you wish to implement.

Contact and License

loreplotR was developed by Sebastian Proost at the RaesLab (part of VIB and KULeuven)and was adopted from code written by Sara Vieira-Silva. loreplotR is available under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International license.