-2

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.

Community
  • 1
  • 1
Swastik
  • 101
  • 9
  • 1
    what plot are you referring to? scatter plot or bar chart? keep in mind that scatter plot is NOT for categorial variables. – Randy Lai Dec 20 '14 at 06:17
  • You you please include a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) that generates the error? – MrFlick Dec 20 '14 at 06:17
  • 1
    @Swastik According to `?pairs` `x: the coordinates of points given as numeric columns of a matrix or data frame. Logical and factor columns are converted to numeric in the same way that ‘data.matrix’ does.` – akrun Dec 20 '14 at 06:17
  • 2
    I don't understand why you want to use a scatter plot for categorial variables. Instead, you should use a box plot. For example, `boxplot(Sepal.Length~Species ,data=iris)` – Randy Lai Dec 20 '14 at 06:38
  • Is there a way to plot boxplot simultaneously for all variables? I am doing this at very initial stage of exploratory analysis. It is just about displaying values at y-axis not any additional feature, I think it should be possible. – Swastik Dec 20 '14 at 07:04

1 Answers1

0

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")
Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294
Swastik
  • 101
  • 9