Learn R Programming

⚠️There's a newer version (0.6.0) of this package.Take me there.

ggpubr: 'ggplot2' Based Publication Ready Plots

ggplot2 by Hadley Wickham is an excellent and flexible package for elegant data visualization in R. However the default generated plots requires some formatting before we can send them for publication. Furthermore, to customize a ggplot, the syntax is opaque and this raises the level of difficulty for researchers with no advanced R programming skills.

The 'ggpubr' package provides some easy-to-use functions for creating and customizing 'ggplot2'- based publication ready plots.

Installation and loading

  • Install from CRAN as follow:
install.packages("ggpubr")
  • Or, install the latest version from GitHub as follow:
# Install
if(!require(devtools)) install.packages("devtools")
devtools::install_github("kassambara/ggpubr")

Geting started

Find out more at http://www.sthda.com/english/rpkgs/ggpubr.

Density and histogram plots

library(ggpubr)
#> Loading required package: ggplot2
# Create some data format
# +++++++++++++++++++++++++++++++++++++++++++
set.seed(1234)
wdata = data.frame(
   sex = factor(rep(c("F", "M"), each=200)),
   weight = c(rnorm(200, 55), rnorm(200, 58)))
head(wdata, 4)
#>   sex   weight
#> 1   F 53.79293
#> 2   F 55.27743
#> 3   F 56.08444
#> 4   F 52.65430

# Density plot with mean lines and marginal rug
# +++++++++++++++++++++++++++++++++++++++++++
# Change outline and fill colors by groups ("sex")
# Use custom palette
ggdensity(wdata, x = "weight",
   add = "mean", rug = TRUE,
   color = "sex", fill = "sex",
   palette = c("#00AFBB", "#E7B800"))

# Histogram plot with mean lines and marginal rug
# +++++++++++++++++++++++++++++++++++++++++++
# Change outline and fill colors by groups ("sex")
# Use custom color palette
gghistogram(wdata, x = "weight",
   add = "mean", rug = TRUE,
   color = "sex", fill = "sex",
   palette = c("#00AFBB", "#E7B800"))

Box plots and violin plots

# Load data
data("ToothGrowth")
df <- ToothGrowth
head(df, 4)
#>    len supp dose
#> 1  4.2   VC  0.5
#> 2 11.5   VC  0.5
#> 3  7.3   VC  0.5
#> 4  5.8   VC  0.5

# Box plots with jittered points
# ++++++++++++++++++++++++++++++++
# Change outline colors by groups: dose
# Use custom color palette
# Add jitter points and change the shape by groups
 ggboxplot(df, x = "dose", y = "len",
    color = "dose", palette =c("#00AFBB", "#E7B800", "#FC4E07"),
    add = "jitter", shape = "dose")

 
# Violin plots with box plots inside
# +++++++++++++++++++++++++++++++++
# Change fill color by groups: dose
# add boxplot with white fill color
ggviolin(df, x = "dose", y = "len", fill = "dose",
   palette = c("#00AFBB", "#E7B800", "#FC4E07"),
   add = "boxplot", add.params = list(fill = "white"))

More

Find out more at http://www.sthda.com/english/rpkgs/ggpubr.

Copy Link

Version

Install

install.packages('ggpubr')

Monthly Downloads

222,798

Version

0.1.0

License

GPL-2

Maintainer

Alboukadel Kassambara

Last Published

July 20th, 2016

Functions in ggpubr (0.1.0)

desc_statby

Descriptive statistics by groups
ggbarplot

Bar plot
ggboxplot

Box plot
ggecdf

Empirical cumulative density function
diff_express

Differential gene expression analysis results
ggdotchart

Cleveland's Dot Plots
ggdensity

Density plot
ggdotplot

Dot plot
gghistogram

Histogram plot
ggerrorplot

Visualizing Error
ggline

Line plot
ggpie

Pie chart
ggpar

Graphical parameters
show_line_types

Line types available in R
show_point_shapes

Point shapes available in R
ggscatter

Scatter plot
ggmaplot

MA-plot from means and log fold changes
ggviolin

Violin plot
ggstripchart

Stripcharts
ggqqplot

QQ Plots
theme_pubr

Publication ready theme
stat_chull

Plot convex hull of a set of points
stat_conf_ellipse

Plot confidence ellipses.
stat_mean

Draw group mean points