有没有办法在Plotly中隐藏跟踪名称(特别是R)?

问题描述 投票:2回答:1

我一直在喋喋不休地讨论如何用剧情摆脱痕迹名称,似乎无法找到任何东西。似乎添加跟踪名称是绘图箱图的独特功能。我可以命名为“”,但我需要原始的跟踪名称,以便在覆盖标记时可以引用它。我已经尽可能地简化了代码以解决根本问题。有没有办法隐藏跟踪名称?

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)
            )
r plotly r-plotly
1个回答
2
投票

如果要在框图中隐藏跟踪名称,可以使用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

enter image description here