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

huangapple go评论72阅读模式
英文:

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

问题

我想在平行坐标图的每行左侧只显示一次标签。我只能在每个实例上获得标签,所以看起来不清晰。

## 测试数据集
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)
)

# 使用GGally中的ggparcoord()构建平行坐标图
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))

有人有什么想法吗?
最好的祝福
wbart

英文:

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 &lt;- data.frame(
  &quot;geneSymbol&quot; = paste(&quot;Gene&quot;, 1:10),
  &quot;condition1&quot; = rnorm(10, 3, 1),
  &quot;condition2&quot; = rnorm(10, 4, 0.5),
  &quot;condition3&quot; = rnorm(10, 7, 0.3)
  )

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

Does anyone has an idea?
Best regards
wbart

答案1

得分: 0

你可以使用ifelse函数使标签依赖于x轴的值。

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)

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

英文:

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

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

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

huangapple
  • 本文由 发表于 2023年8月8日 20:06:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/76859401.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定