How to display Factor values in plots?

975 views Asked by At

When plotting variables of data type factor in R, the Y-axis graph shows the factor levels (i.e numbers), not the name of factors especially when plotting using pairs() function. Is there any way to display the names of the factors at both axes?

I have tried converting variable to character using as.character(), but it didn't work because R throws an error. As an example below code produces attached image

library(ISLR)

pairs(Wage)

Variables like jobclass, health are factors and I want graph to display name of the factors instead of numbers. Cannot post images due to low reputation.

1

There are 1 answers

1
Swastik On BEST ANSWER

ggpairs() function from GGally can produce the graphs along with colours and factor names. The downside is it is considerably slower than pairs()

library(GGally)
library(ISLR)
attach(Wage)
ggpairs(Wage[,c("education","jobclass","health","wage")], colour="race")