R - plotly - hide colorbar

﹥>﹥吖頭↗ 提交于 2021-01-02 05:53:59

问题


How can I hide the colorbar in the following plotly example taken from their website?

    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)

The figure reference does not provide an answer: https://plot.ly/r/reference/#colorbar. I can hide the colorbar via editing the graph, but I would like to control this in the R code.


回答1:


Try adding showscale = FALSE at the trace level.

https://plot.ly/r/reference/#heatmap-showscale




回答2:


Another option is to use %>% hide_colorbar()




回答3:


I ended up here searching for it in JavaScript. For JS use showscale :false after chart type:-

   showscale :false,
   type: 'heatmap',


来源:https://stackoverflow.com/questions/32297832/r-plotly-hide-colorbar

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!