View source: R/e_plot_corr_ellipse.R
e_plot_corr_ellipse | R Documentation |
Correlation plot with ellipses
e_plot_corr_ellipse(
corr,
outline = FALSE,
col = "grey",
upper.panel = c("ellipse", "number", "none")[1],
lower.panel = c("ellipse", "number", "none")[2],
diag = c("none", "ellipse", "number")[3],
digits = 2,
bty = "n",
axes = FALSE,
xlab = "",
ylab = "",
asp = 1,
cex.lab = par("cex.lab"),
cex = 0.75 * par("cex"),
mar = c(0, 0, 1, 0),
...
)
corr |
correlation matrix |
outline |
option |
col |
option |
upper.panel |
option |
lower.panel |
option |
diag |
option |
digits |
option |
bty |
option |
axes |
option |
xlab |
option |
ylab |
option |
asp |
option |
cex.lab |
option |
cex |
option |
mar |
option |
... |
option |
invisible(NULL)
datasets::mtcars |> cor() |> e_plot_corr_ellipse()
## Not run:
## Color version
# use mtcars since all numeric
tab_cor <-
datasets::mtcars |>
as.matrix() |>
Hmisc::rcorr(
type = c("pearson", "spearman")[1]
)
tab_cor$r
# red neg, white 0, blue pos
color_scale <-
c(
rgb(241, 54, 23, maxColorValue = 255)
, "white"
, rgb( 0, 61, 104, maxColorValue = 255)
)
# color ramp in "Lab" space
color_ramp <- colorRampPalette(color_scale, space = "Lab")
# Create scale with 200 points
colors_plot <- color_ramp(100)
# move correlation range from [-1, 1] to [0, 100] for colors
tab_cor$r |>
e_plot_corr_ellipse(
col = colors_plot[round(((tab_cor$r + 1)/2) * 100)]
, main = "Colored ellipses"
, upper.panel = c("ellipse", "number", "none")[1]
, lower.panel = c("ellipse", "number", "none")[2]
, diag = c("none", "ellipse", "number")[3]
, digits = 3
)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.