Description Usage Arguments Value Author(s) See Also Examples
View source: R/epi_plot_heatmap_triangle.R
Plot correlations between numeric variables as a triangle heatmap using ggplot2. Prettier plot than a simple heatmap with only the lower triangle of a correlation matrix. Pass the correlation values from a melted (long) correlation matrix as input. Requires a data.frame with correlations and a data.frame with matching p-values. Column headers in both must be called Var1 and Var2. Use the output from epi_stats_corr_triangle() for example. cor_method is a string passed to the legend title It expects the name of the method used for correlation (eg 'Spearman')
1 2 3 | epi_plot_heatmap_triangle(cormat_melted_triangle_r = NULL,
cormat_melted_triangle_pval = NULL, cor_method = "Spearman",
show_values = "pval")
|
cormat_melted_triangle_r |
a matrix object with correlation values Usually the output of episcout::epi_stats_corr_triangle(). |
cormat_melted_triangle_pval |
a matrix object with correlation p-values Usually the output of episcout::epi_stats_corr_triangle(). |
cor_method |
Correlation method used, will be printed in plot. Default is 'Spearman' |
show_values |
Values to show in plot, 'pval' or 'corr'. Default is 'pval'. |
Returns a heatmap as a ggplot2 object
Antonio Berlanga-Taylor <https://github.com/AntonioJBT/episcout>
epi_stats_corr
, epi_stats_corr_triangle
,
epi_stats_corr_rename
, epi_plot_heatmap
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 | ## 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)
epi_plot_heatmap_triangle(renamed_triangles$cormat_melted_triangle_r,
renamed_triangles$cormat_melted_triangle_pval,
show_values = 'pval'#'corr'
)
ggsave('epi_heatmap_triangle.svg',
height = 12,
width = 12,
units = 'in'
)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.