简体   繁体   English

从图中删除连续的图例

[英]Remove continuous legend from plotly

I have a basic scatterplot that I've made in plotly (in R). 我有一个用散点图(在R中)制作的基本散点图。 I'm using a continuous input to color the data points which plotly converts into a gradient. 我正在使用连续输入来为数据点着色,这些数据点会以图形方式转换为渐变。 However, the removelegend option doesn't remove a continuous legend the way it removes a discrete legend. 但是, removelegend选项不会像删除离散图例那样删除连续图例。 Consider the example below. 考虑下面的示例。

data = mtcars
data$vs = as.character(data$vs)

plotly::plot_ly(
  data = data,
  x = ~disp,
  y = ~mpg,
  color = ~vs,
  mode = "markers",
  type = "scatter"
) %>% 
  layout(showlegend = FALSE)

第一个示例图片,无图例

plotly::plot_ly(
  data = data,
  x = ~disp,
  y = ~mpg,
  color = ~hp,
  mode = "markers",
  type = "scatter"
) %>% 
  layout(showlegend = FALSE)

第二个示例图像,图例存在

Is there a way to remove the continuous legend? 有没有办法删除连续的图例?

The issue arises because in the continuous case plotly doesn't call it a legend, it's a color bar. 之所以出现此问题,是因为在连续情况下,plotly不会将其称为图例,而是一个颜色条。 The easiest way to remove it is to pipe in hide_colorbar() 删除它的最简单方法是在hide_colorbar()进行管道hide_colorbar()

plotly::plot_ly(
  data = data,
  x = ~disp,
  y = ~mpg,
  color = ~hp,
  mode = "markers",
  type = "scatter"
) %>% 
  hide_colorbar()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM