-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathREADME.Rmd
77 lines (61 loc) · 2.54 KB
/
README.Rmd
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
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# ggordiplots
<!-- badges: start -->
[![R-CMD-check](https://github.com/jfq3/ggordiplots/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/jfq3/ggordiplots/actions/workflows/R-CMD-check.yaml)
[![Github All Releases](https://img.shields.io/github/downloads/jfq3/ggordiplots/total.svg)])
<!-- badges: end -->
The `vegan` package includes several functions for adding features to ordination plots: `ordiarrows()`, `ordiellipse()`, `ordihull()`, `ordispider()` and `ordisurf()`. This package adds these same features to ordination plots made with `ggplot2`. In addition, `gg_ordibubble()` sizes points relative to the value of an environmental variable.
The functions are written so that features from each can be combined in customized ordination plots.
The functions `ord_labels()` and `scale_arrow()` (used to ensure vector arrows fit within a plot) are exported to make it easier to generate custom ordination plots.
## Installation
You can install the development version of ggordiplots from [GitHub](https://github.com/) with:
``` r
# install.packages("devtools")
devtools::install_github("jfq3/ggordiplots")
```
You can install the latest release from CRAN with:
``` r
install.packages("ggordiplots")
```
## Examples
Plot an ordination with ellipses around treatment group centroids (at distances of one standard deviation) with `gg_ordiplot()`.
```{r}
library(ggordiplots)
data("dune")
data("dune.env")
dune_bray <- vegdist(dune, method = "bray")
ord <- cmdscale(dune_bray, k = (nrow(dune) - 1), eig = TRUE, add = TRUE)
plt1 <- gg_ordiplot(ord, groups = dune.env$Management, plot = FALSE)
```
`plt1` is list with items named:
```{r}
names(plt1)
```
The first 5 items are data frames for making plots. The last item is a ggplot:
```{r}
plt1$plot
```
Fit a vector of Al concentrations to the ordination with `gg_envfit()`.
```{r}
Al <- as.data.frame(dune.env$A1)
colnames(Al) <- "Al"
plt2 <- gg_envfit(ord, env = Al, groups = dune.env$Management, plot = FALSE)
plt2$plot
```
Add ellipses from the first plot to the second plot. The resulting plot can be further customized using usual `ggplot2` methods. For example, change the legend title.
```{r}
plt2$plot +
geom_path(data = plt1$df_ellipse, aes(x=x, y=y, color=Group)) +
guides(color=guide_legend(title="Management")) # Change legend title
```