6

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)
            )
robotvsbears
  • 63
  • 1
  • 3
  • Welcome to Stackoverflow! Where are you trying to hide the trace name? In the y-axis or in the hover info? – Maximilian Peters Aug 29 '18 at 16:45
  • Thanks Max! I'm trying to hide the trace name on the y-axis. Hover Info can be customized in the Layout if I remember correctly so I'm not too worried about that. – robotvsbears Aug 30 '18 at 17:48

1 Answers1

5

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

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

enter image description here

Maximilian Peters
  • 30,348
  • 12
  • 86
  • 99