```{r, include = FALSE}
knitr::opts_chunk$set(
message = FALSE,
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
fig.align = "center",
out.width = "100%"
)
```
# ggcor
The goal of `ggcor` is to provide a set of functions that can be used to visualize a correlation matrix quickly.
## Installation
Now `ggcor` is not on cran, You can install the development version of ggcor from [GitHub](https://github.com/) with:
``` r
# install.packages("devtools")
devtools::install_github("houyunhuang/ggcor")
```
If you are in the mainland of China, you can install ggcor from
[Gitee](https://gitee.com) with:
``` r
# install.packages("devtools")
devtools::install_git("https://gitee.com/houyunhuang/ggcor.git")
```
## Correlation plot
```{r example01}
library(ggplot2)
library(ggcor)
set_scale()
quickcor(mtcars) + geom_square()
quickcor(mtcars, type = "upper") + geom_circle2()
quickcor(mtcars, cor.test = TRUE) +
geom_square(data = get_data(type = "lower", show.diag = FALSE)) +
geom_mark(data = get_data(type = "upper", show.diag = FALSE), size = 2.5) +
geom_abline(slope = -1, intercept = 12)
```
## Mantel test plot
```{r example03,fig.height=4.6}
library(dplyr)
data("varechem", package = "vegan")
data("varespec", package = "vegan")
mantel %
mutate(rd = cut(r, breaks = c(-Inf, 0.2, 0.4, Inf),
labels = c("< 0.2", "0.2 - 0.4", ">= 0.4")),
pd = cut(p.value, breaks = c(-Inf, 0.01, 0.05, Inf),
labels = c("< 0.01", "0.01 - 0.05", ">= 0.05")))
quickcor(varechem, type = "upper") +
geom_square() +
anno_link(aes(colour = pd, size = rd), data = mantel) +
scale_size_manual(values = c(0.5, 1, 2)) +
scale_colour_manual(values = c("#D95F02", "#1B9E77", "#A2A2A288")) +
guides(size = guide_legend(title = "Mantel's r",
override.aes = list(colour = "grey35"),
order = 2),
colour = guide_legend(title = "Mantel's p",
override.aes = list(size = 3),
order = 1),
fill = guide_colorbar(title = "Pearson's r", order = 3))
```
## Circular heatmap
```{r,fig.height=7}
rand_correlate(100, 8) %>% ## require ambient packages
quickcor(circular = TRUE, cluster = TRUE, open = 45) +
geom_colour(colour = "white", size = 0.125) +
anno_row_tree() +
anno_col_tree() +
set_p_xaxis() +
set_p_yaxis()
```
## General heatmap
```{r,fig.height=7}
d1 %
gcor_tbl(cluster = TRUE)
p %
gcor_tbl(name = "Type", row.order = d1) %>%
qheatmap(aes(fill = Type)) + coord_fixed() + remove_y_axis()
d2