使用 plotly 时图例中的颜色条

编程入门 行业动态 更新时间:2024-10-08 13:35:51
本文介绍了使用 plotly 时图例中的颜色条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这是我的数据:

set.seed(42) mydata = data.frame(A = rnorm(20), B = rnorm(20), Index = sample(190:400,20))

我试图根据 Index 值将数据划分为 20 个不同的区间,然后根据它们的区间 value 为散点着色.下面是我的代码.它工作不完美.

I am trying to divide the data into 20 different intervals based on the Index value and then color the scatter points according to their interval value. Below is my code. It is not working perfectly.

cols = colorRampPalette(c("red", "black"), space = "rgb")(20) mydata$interval = cut(mydata$Index,breaks = 20) mydata$cols = cols[mydata$interval] require(plotly) x = list(title = "A") y = list(title = "B") plot_ly(mydata, x = ~A, y = ~B, color = ~cols, type = "scatter", mode = 'markers', hoverinfo = 'text', text = ~paste(interval)) %>% layout(xaxis = x, yaxis = y)

如何在颜色基于的图例中获得 colorbar索引值.

How do I get a colorbar in the legend where the colors are based on Index value.

推荐答案

你在找这个吗:

plot_ly(mydata, x = ~A, y = ~B, type = "scatter", mode = 'markers', hoverinfo = 'text', colors = colorRampPalette(c("red", "black"), space = "rgb")(20), color = ~Index, text = ~paste(interval), marker = list(size=14)) %>% layout(xaxis = x, yaxis = y) %>% colorbar(title = "My Legend")

更多推荐

使用 plotly 时图例中的颜色条

本文发布于:2023-07-19 13:43:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1157084.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图例   颜色   plotly

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!