creating labels in parallel coordinates plot with R, ggparcoord()

142 Views Asked by At

I want to have labels only one time on the left of each line in a parallel coordinates plot. I only managed to get labels on every instances so it doesn't look clear.

## test data set
data2 <- data.frame(
  "geneSymbol" = paste("Gene", 1:10),
  "condition1" = rnorm(10, 3, 1),
  "condition2" = rnorm(10, 4, 0.5),
  "condition3" = rnorm(10, 7, 0.3)
  )

#building parallel coordination plot with ggparcoord() from GGally
ggparcoord(data= data2,
           columns = 2:4,
           groupColumn = 1,
           scale = "std",
           scaleSummary = "mean",
           centerObsID = 1,
           missing = "exclude",
           showPoints = FALSE,
           splineFactor = FALSE,
           alphaLines = 1,
           boxplot = TRUE,
           shadeBox = NULL,
           mapping = NULL,
           title = "TEST")+
  geom_text(aes(label=geneSymbol))

Does anyone has an idea? Best regards wbart

1

There are 1 best solutions below

1
Allan Cameron On BEST ANSWER

You can make the labels dependent on the x axis value using ifelse

ggparcoord(data= data2,
           columns = 2:4,
           groupColumn = 1,
           scale = "std",
           scaleSummary = "mean",
           centerObsID = 1,
           missing = "exclude",
           showPoints = FALSE,
           splineFactor = FALSE,
           alphaLines = 1,
           boxplot = TRUE,
           shadeBox = NULL,
           mapping = NULL,
           title = "TEST") +
  geom_text(aes(label = ifelse(variable == "condition1", 
                               as.character(geneSymbol), "")), hjust = 1.2)

enter image description here