Search code examples
rgraphlatticeparallel-coordinates

automatically adding labels to x axis in parallel coordinates (parallelplot()) R


I'm using the parallelplot() function from the lattice library in R and I'm trying to figure how to add labels to the x axis on the left hand side.

My problem is that the documentation for this function doesn't really tell you how? So far all I've seen is that I'm able to create the graph then modify the axis manually.

Is there a better way? enter image description here

above is picture of my graph, I'm trying to automatically add the names of the groups on the x axis.


Solution

  • Labels are based on the names of the columns, which you can set however you like. Judging from your output it seems like you did not name the columns of your data.frame.

    library(lattice)
    
    dat <- data.frame(
      One = rnorm(10),
      Two = rnorm(10, 2, 1),
      "Some name" = rnorm(10, 4, 0.1),
      check.names = FALSE #or you'll get periods instead of spaces
    )
    
    parallelplot(~ dat, horizontal.axis = FALSE)
    

    enter image description here