epi_plot_heatmap: Plot a simple heatmap using ggplot2

Description Usage Arguments Value Author(s) See Also Examples

View source: R/epi_plot_heatmap.R

Description

Plot correlations between numeric variables as a heatmap using ggplot2. Pass the correlation values from a melted (long) correlation matrix as input.

Usage

1
2
epi_plot_heatmap(cormat_melted = "cormat_all$cormat_melted_r",
  title = "")

Arguments

cormat_melted

a matrix object (usually the output of Hmisc::rcorr() r (or P) or episcout::epi_stats_corr()). Default is 'cormat_all$cormat_melted_r'

title

Main title for the plot. Default is blank (”)

Value

Returns a heatmap as a ggplot2 object

Author(s)

Antonio Berlanga-Taylor <https://github.com/AntonioJBT/episcout>

See Also

epi_stats_corr, epi_stats_corr_triangle, epi_stats_corr_rename, epi_plot_heatmap_triangle

Examples

 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
## Not run: 
df <- data.frame(var_id = rep(1:(n / 2), each = 2),
var_to_rep = rep(c("Pre", "Post"), n / 2),
x = rnorm(n),
y = rbinom(n, 1, 0.50),
z = rpois(n, 2)
)
df_corr <- df %>% select_if(~ epi_clean_cond_numeric(.))
df_corr <- df_corr[, -1] # exclude var_id
cormat_all <- epi_stats_corr(df_corr, method = 'pearson')
melted_triangles <- epi_stats_corr_triangle(cormat = cormat_all$cormat)
vars_list <- c('x', 'y', 'z')
var_labels <- c('numeric', 'binomial', 'poisson')
renamed_triangles <- epi_stats_corr_rename(melted_triangles$cormat_melted_triangle_r,
                                           melted_triangles$cormat_melted_triangle_pval,
                                           vars_list = vars_list,
                                           var_labels = var_labels
                                           )
library(ggplot2)
library(ggthemes)
epi_plot_heatmap(cormat_all$cormat_melted_r)
epi_plot_heatmap(renamed_triangles$cormat_melted_triangle_r)
epi_plot_heatmap(renamed_triangles$cormat_melted_triangle_pval)
ggsave('my_heatmap.svg')

## End(Not run)

AntonioJBT/episcout documentation built on Nov. 7, 2019, 5:34 p.m.