如何解决使用`plot_ly`的线条和标记的自定义颜色出现问题 完整代码:
让我们假设我要对线条+标记的绘图使用自定义颜色。
使用colors
的{{1}}和color
参数非常简单,但是一旦我想自己修改标记(使用plot_ly()
参数),我就会遇到困难并在网上找不到解决此特定问题的帮助。
有人可以告诉我我在做什么错吗?
marker
解决方法
这似乎有些奇怪,但是您遇到的最简单的解决方案是删除:
line = list(color = scales::hue_pal()(n_distinct(tmp$class))))
并且仅包括:
line = list(width = 3)
这是您的情节:
完整代码:
# Underlying data
tmp <- mpg %>%
group_by(class,manufacturer) %>%
summarise(models=n())
# Issue with markers > idea behind is to have a white center and a marker line with the same color as the line itself
tmp %>%
plot_ly(x=~manufacturer,y=~models,group=~class,type="scatter",color=~class,colors = scales::hue_pal()(n_distinct(tmp$class)),marker = list(color = 'rgba(255,255,1)',line = list(width = 3)),mode="lines+markers")
tmp
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。