knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "README-",
  dev = "png"

)

ggords

The package provides six functions: ggpca(), ggca(), ggpcoa(), ggnmds(), ggrda(), ggcca(). You can customize the display labels and themes. Labels can contain formulas. Image themes can be set by themes in ggplots or by other packages(ggthemr).

Installation

library(devtools)
install_github("wdy91617/ggords")

Example Usage

library(ggords)
require(vegan)
require(ggplot2)
data(Envs)

ggpca

1. get group factor

Env.w <- hclust(dist(scale(Envs)), "ward.D")
gr <- cutree(Env.w , k=4)
grl <- factor(gr)

2. Compute PCA

Env.pca <- rda(Envs,scale = TRUE)
#head(summary(Env.pca))

3. Produce a plot

ggpca(Env.pca)

4. Add a group

ggpca(Env.pca, group = grl) 

5. Set a theme

ggpca(Env.pca, group = grl, spacol = "white") + theme_dark()

6. Set a theme (use ggthemr packages, more themes in ggthemer)

library(ggthemr)

chalk_theme <- ggthemr('chalk', set_theme = FALSE)
fd_theme <- ggthemr('flat dark', set_theme = FALSE)

p <- ggpca(Env.pca, group = grl, spacol = "white")
p + chalk_theme$theme
p + fd_theme$theme

7. Remove the arrow

ggpca(Env.pca, group = grl, spearrow = NULL)

8. Modify legend title, group color and point shape

ggpca(Env.pca, group = grl, spearrow = NULL) + 
  scale_color_manual(name = "Groups",values = c("red2", "purple1", "grey20","cyan")) +
  scale_shape_manual(name = "Groups",values = c(8,15,16,17))

9. Add confidence ellipses

ggpca(Env.pca, group = grl, spearrow = NULL, ellipse = TRUE) +
  scale_colour_hue(l = 70, c = 300)

ggpnmds

1. Compute NMDS

Env.nmds <- metaMDS(Envs, distance="bray")
#head(summary(Env.nmds))

2. Produce a plot

ggnmds(Env.nmds)

3. Add a group

ggnmds(Env.nmds, group = grl) 

4. Set a theme

ggnmds(Env.nmds, group = grl, spacol = "white") + theme_dark()

5. Set a theme (use ggthemr packages, more themes in ggthemer)

library(ggthemr)

chalk_theme <- ggthemr('chalk', set_theme = FALSE)
fd_theme <- ggthemr('flat dark', set_theme = FALSE)

p <- ggnmds(Env.nmds, group = grl, spacol = "white")
p + chalk_theme$theme
p + fd_theme$theme

6. Remove the arrow

ggnmds(Env.nmds, group = grl, spearrow = NULL)

7. Set labels

mlabs<-c("NH[4]^{`+`}" , "NO[3]^{`-`}" ,"delta^13*C","A[1]","sqrt(2*pi)","frac(x^2,2)",
         "sin(x)","hat(x)","bar(xy)","90*degree","x^{y+z}")

ggnmds(Env.nmds, group = grl, spearrow = NULL, msplabs = mlabs)

8. Modify legend title, group color and point shape

ggnmds(Env.nmds, group = grl, spearrow = NULL) + 
  scale_color_manual(name = "Groups",values = c("red2", "purple1", "grey20","cyan")) +
  scale_shape_manual(name = "Groups",values = c(8,15,16,17))

9. Add confidence ellipses

ggnmds(Env.nmds, group = grl, spearrow = NULL, ellipse = TRUE) +
  scale_colour_hue(l = 70, c = 300)

License

Released under GPL-3.



wdy91617/ggords documentation built on May 24, 2019, 2:47 p.m.