使用`plot_ly`的线条和标记的自定义颜色出现问题 完整代码:

问题描述

让我们假设我要对线条+标记的绘图使用自定义颜色。 使用colors的{​​{1}}和color参数非常简单,但是一旦我想自己修改标记(使用plot_ly()参数),我就会遇到困难并在网上找不到解决此特定问题的帮助。 有人可以告诉我我在做什么错吗?

marker

解决方法

这似乎有些奇怪,但是您遇到的最简单的解决方案是删除:

line = list(color = scales::hue_pal()(n_distinct(tmp$class))))

并且仅包括:

line = list(width = 3)

这是您的情节:

enter image description here

完整代码:

# 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

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...