R - Plotly - 隐藏色条

11
我该如何在以下的 Plotly 示例中隐藏 colorbar?
请按照以下方式操作:
    df <- read.csv('https://raw.githubusercontent.com/plotly/datasets/master/2014_world_gdp_with_codes.csv')

# light grey boundaries
l <- list(color = toRGB("grey"), width = 0.5)

# specify map projection/options
g <- list(
  showframe = FALSE,
  showcoastlines = FALSE,
  projection = list(type = 'Mercator')
)

plot_ly(df, z = GDP..BILLIONS., text = COUNTRY, locations = CODE, type = 'choropleth',
        color = GDP..BILLIONS., colors = 'Blues', marker = list(line = l),
        colorbar = list(tickprefix = '$', title = 'GDP Billions US$'),
        filename="r-docs/world-choropleth") %>%
  layout(title = '2014 Global GDP<br>Source:<a href="https://www.cia.gov/library/publications/the-world-factbook/fields/2195.html">CIA World Factbook</a>',
         geo = g)

图表参考文档没有提供答案:https://plot.ly/r/reference/#colorbar。我可以通过编辑图表来隐藏颜色条,但我希望在R代码中控制它。

3个回答

21

另一种选择是使用 %>% hide_colorbar()


1
这个可以,似乎showscale=FALSE不再起作用了。好耶! - Benbob
@Benbob 对我来说有效,尽管不是在layout()中,而是在plot_ly()中。 - andschar

20

1
这在Python中也可以工作,谢谢!'showscale': False - S3DEV

3

我是在搜索JavaScript相关内容时来到这里的。对于JS,请在图表类型后面添加showscale :false

   showscale :false,
   type: 'heatmap',

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接