有没有办法在Plotly(特别是R)中隐藏跟踪名称? [英] Is there a way to hide Trace Names in Plotly (specifically R)?

查看:147
本文介绍了有没有办法在Plotly(特别是R)中隐藏跟踪名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在绞尽脑汁地想办法如何用阴谋摆脱痕迹名称,而且似乎找不到任何东西.似乎添加跟踪名称是密谋箱图的独特功能.我可以将其命名为",但是我需要原始的跟踪名称,以便在覆盖标记时可以引用它.我已将代码尽可能简化为根本问题.有没有办法隐藏跟踪名称?

I've been wracking my brain over how to get rid of the trace name with plotly and can't seem to find anything. It seems adding the trace name is a unique feature of plotly boxplots. I could just name it " " but I need the original trace name so that I can reference it when overlaying a marker. I've simplified the code as much as possible to the root issue. Is there a way to hide the trace name?

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)
            )

推荐答案

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

If yoo want to hide the trace names in a box chart, you could hide the axis' labels by using showticklabels = F.

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

In the example below the trace name is also hidden in the hover labels by setting 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

这篇关于有没有办法在Plotly(特别是R)中隐藏跟踪名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆