问题描述
让我们假设我要对线条+标记的绘图使用自定义颜色。
使用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