I like to have the labels of each line of a parallel coordination plot once left beside each line. I tried to use the solution from @Allan Cammeron on another dataset and run into the problem that if I select the first column the text labels are transfered into numbers. If I choose the second columns everthing works fine. Does anyone know why this happens?
#creating test data
data3 <- tibble(
SeqName = paste(rep(c(
"Gene1", "Gene2", "Gene3"
), 3)),
type = paste(c(
rep("nonresponder", 3),
rep("norm responder", 3),
rep("high responder", 3)
)),
time1 = rnorm(9, 2, 0.5),
time2 = rnorm(9, 4, 1),
time3 = rnorm(9, 6, 1)
)
# now the parallel coordinates plot
ggparcoord(
data = data3,
columns = 3:5,
groupColumn = 2,
showPoints = FALSE,
splineFactor = FALSE,
alphaLines = 1,
boxplot = TRUE
) +
geom_text_repel(
aes(label = ifelse(
variable == "time1",
as.character(SeqName), ""
)),
hjust = 1.2,
size = 5,
direction = "y"
) +
theme(text = element_text(size = 15))
Thank you wbart
The issue is that under the hood all character
s or factor
s (except for the groupColumn
) are converted to numerics. Hence, when using one of these columns for the labels you end up with numbers.
One workaround would be to store the labels or levels from the original dataset in a lookup vector which could then be used to assign the correct label to the numerics:
library(ggplot2)
library(GGally)
library(ggrepel)
set.seed(123)
seqname_levels <- levels(factor(data3$SeqName))
ggparcoord(
data = data3,
columns = 3:5,
groupColumn = 2,
showPoints = FALSE,
splineFactor = FALSE,
alphaLines = 1,
boxplot = TRUE
) +
geom_text_repel(
aes(label = ifelse(
variable == "time1",
seqname_levels[SeqName], ""
)),
hjust = 1.2,
size = 5,
direction = "y"
) +
theme(text = element_text(size = 15))