【问题标题】:R plotly - showlegend = FALSE does not workR plotly - showlegend = FALSE 不起作用
【发布时间】:2018-04-25 00:12:01
【问题描述】:

为什么showlegend = FALSE 不抑制这个简化的 R 代码中的图例,生成一个散点图?感谢您的帮助。

plot_ly(x =  ~  1:5,  y =  ~ 1:5, type="scatter",mode="markers",
 color =  1:5,
 showlegend = FALSE)

【问题讨论】:

    标签: r plotly


    【解决方案1】:

    plot_ly 中的showlegend 参数仅指因子标签。例如

    plot_ly(x =  ~  1:5,  y =  ~ 1:5, type="scatter",mode="markers",
        color =  as.factor(1:5))
    

    plot_ly(x =  ~  1:5,  y =  ~ 1:5, type="scatter",mode="markers",
        color =  as.factor(1:5), showlegend = FALSE)
    

    很遗憾,showscale 没有针对散点图实现,因此您需要使用不太优雅的 hide_colorbar() 函数来处理色标:

    plot_ly(x =  ~  1:5,  y =  ~ 1:5, type="scatter",mode="markers",
            color =  1:5) %>% hide_colorbar() 
    

    【讨论】:

    • 非常感谢。那肯定是一个快速的答案!
    • 我的荣幸 :) 如果您认为这是一个完整的答案,您应该使用复选标记将其标记为“已回答”
    猜你喜欢
    • 2018-07-14
    • 2021-12-11
    • 1970-01-01
    • 2021-11-10
    • 1970-01-01
    • 2013-09-20
    • 2017-01-02
    • 1970-01-01
    • 2021-12-30
    相关资源
    最近更新 更多