【问题标题】:Is there a way to hide Trace Names in Plotly (specifically R)?有没有办法在 Plotly(特别是 R)中隐藏跟踪名称?
【发布时间】:2019-02-04 12:43:04
【问题描述】:

我一直在绞尽脑汁思考如何使用 plotly 摆脱跟踪名称,但似乎找不到任何东西。似乎添加跟踪名称是情节箱线图的独特功能。我可以将其命名为“”,但我需要原始跟踪名称,以便在覆盖标记时可以引用它。我已将代码尽可能简化为根本问题。有没有办法隐藏跟踪名称?

housing = read.table("http://archive.ics.uci.edu/ml/machine-learning-databases/housing/housing.data")
colnames(housing) = c("CRIM","ZN","INDUS","CHAS","NOX","RM","AGE","DIS","RAD","TAX","PTRATIO","B","LSTAT","MEDV")

housing %>%
  plot_ly( x = ~RM, 
        type="box", 
        name = "RM",
        showlegend = FALSE
        ) %>% 
  add_markers(x=6, y="RM",
            marker = list(color = "blue", size = 15)
            )

【问题讨论】:

  • 欢迎来到 Stackoverflow!您要在哪里隐藏跟踪名称?在 y 轴还是在悬停信息中?
  • 谢谢麦克斯!我试图隐藏 y 轴上的跟踪名称。如果我没记错的话,悬停信息可以在布局中自定义,所以我不太担心。

标签: r plotly r-plotly


【解决方案1】:

如果您想在箱形图中隐藏轨迹名称,可以使用 showticklabels = F 隐藏轴的标签。

在下面的示例中,跟踪名称也通过设置hoverinfo = 'x' 隐藏在悬停标签中。

library(plotly)
housing = read.table("http://archive.ics.uci.edu/ml/machine-learning-databases/housing/housing.data")
colnames(housing) = c("CRIM","ZN","INDUS","CHAS","NOX","RM","AGE","DIS","RAD","TAX","PTRATIO","B","LSTAT","MEDV")

housing %>%
  plot_ly( x = ~RM,
           y = 'RM',
           type="box", 
           name = "RM",
           showlegend = FALSE,
           hoverinfo = 'x'
  ) %>% 
  add_markers(x=6, y="RM",
              marker = list(color = "blue", size = 15)
  ) %>% layout(yaxis = list(showticklabels = F))
housing

【讨论】:

  • 谢谢马克西米利安你的统治!
猜你喜欢
  • 1970-01-01
  • 2019-08-07
  • 2011-10-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-29
  • 2021-09-02
相关资源
最近更新 更多