Selrac
Selrac

Reputation: 2293

Visual correlation between numerical and categorical

Is it possible to create a visual correlation map wit numerical and categorical variables?

For example with this values:

val1 <- rep(c(1:2),5)
val2 <- rep(c('a','b'),5)
val3 <- paste(val1,val2)
val4 <- c(1:10)^2
val5 <- paste('x',val4)

Following on the question here I can do see the correlation as a table like:

table(val1,val2)
table(val1,val3)
etc...

This somehow helps, but I'm looking to produce something like a correlation map.

Also, there is a problem as it works between numeric & categorical and categorical & categorical, but it doesn't work with numeric & numeric, like table(val1,val4).

Does anyone has an example of how to achieve a visual correlation representation for mixed numerical & categorical variables?

Upvotes: 0

Views: 2737

Answers (1)

thisisrg
thisisrg

Reputation: 606

Might want to try out the ggpairs function in GGally package. This may not be the exact answer you want (doesn't calculate the correlations) , which may be problematic as far as interpretation goes (see here enter link description here) .This is more for visualization of the variable relationships. If we put val1,val2 and val5 into a df we can visualize this as (not the only option). If you have a correlation matrix then I'd use corrplot from the corrplot package :

ggpairs(df,mapping = ggplot2::aes(color = val2),upper = list(continuous = "cor", discrete = "box"),lower = list(continuous = "cor", discrete="dot"))

Upvotes: 1

Related Questions