Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在R绘图中按组使用RGB客户颜色_R_Plotly - Fatal编程技术网

在R绘图中按组使用RGB客户颜色

在R绘图中按组使用RGB客户颜色,r,plotly,R,Plotly,我有几个系列,我想用plotly R制作动画。在遵循这里的示例()之后,我已经开始制作动画了。我知道了如何更改组的颜色,但是,我需要组的特定颜色(RGB自定义颜色) 我有两个问题: 如何将RGB颜色指定给R中的组…我缺少什么 有没有更简单的方法?我还有几个“城市”而不仅仅是两个,我希望能够动态地指定特定的颜色。我能够把颜色作为数据框中的一列拉进来,并希望能够以这种方式分配它们…使其适用于常规颜色,但需要将其用于RGB library(plotly) #用于创建框架的辅助函数 按% 选择(常规颜色

我有几个系列,我想用plotly R制作动画。在遵循这里的示例()之后,我已经开始制作动画了。我知道了如何更改组的颜色,但是,我需要组的特定颜色(RGB自定义颜色)

我有两个问题:

  • 如何将RGB颜色指定给R中的组…我缺少什么
  • 有没有更简单的方法?我还有几个“城市”而不仅仅是两个,我希望能够动态地指定特定的颜色。我能够把颜色作为数据框中的一列拉进来,并希望能够以这种方式分配它们…使其适用于常规颜色,但需要将其用于RGB
  • library(plotly)
    #用于创建框架的辅助函数
    按%
    选择(常规颜色)%>%
    不同的()%>%
    拉
    RGB_颜色_矢量%
    安排(城市)%%>%
    选择(RGB_颜色)%>%
    不同的()%>%
    拉
    p%
    阴谋(
    x=~日期,
    y=~中位数,
    斯普利特=~城市,
    frame=~frame,
    类型='scatter',
    模式='行',
    行=列表(simplyfy=F),
    颜色=~城市,
    #颜色=c(‘红色’、‘黑色’)
    颜色=c('rgb(229,18,18)','rgb(13,9,9)')
    #颜色=注册颜色向量
    #颜色=RGB_颜色_向量
    ) %>% 
    布局(
    xaxis=列表(
    title=“日期”,
    零线=F
    ),
    yaxis=列表(
    title=“中值”,
    零线=F
    )
    ) %>% 
    动画选择(
    帧=100,
    转换=0,
    重画=假
    ) %>%
    动画滑块(
    隐藏=T
    ) %>%
    动画按钮(
    x=1,xanchor=“right”,y=0,yanchor=“bottom”
    )
    P
    
    rgb()
    是一个输出所需颜色的十六进制值的函数。这就是你需要储存的东西。卸下
    ,它应该可以正常工作。您需要将
    maxColorValue=255
    添加到
    rgb()
    函数中

    d <- 
      txhousing %>%
      filter(year > 2005, city %in% c("Abilene", "Bay Area")) %>%
      accumulate_by(~date) %>%
      mutate(regular_color = if_else(city == "Abilene", 'red', 'black'),
             RGB_color = if_else(city == "Abilene", 
                                 rgb(229, 18, 18, maxColorValue = 255), 
                                 rgb(13, 9, 9, maxColorValue = 255)))
    

    完美的我试着不引用任何引号,但遗漏了
    max
    语句让我感到厌烦。谢谢
    d <- 
      txhousing %>%
      filter(year > 2005, city %in% c("Abilene", "Bay Area")) %>%
      accumulate_by(~date) %>%
      mutate(regular_color = if_else(city == "Abilene", 'red', 'black'),
             RGB_color = if_else(city == "Abilene", 
                                 rgb(229, 18, 18, maxColorValue = 255), 
                                 rgb(13, 9, 9, maxColorValue = 255)))
    
    plot_ly(
      x = ~date, 
      y = ~median,
      split = ~city,
      frame = ~frame, 
      type = 'scatter',
      mode = 'lines', 
      line = list(simplyfy = F),
      color = ~city,
      colors = RGB_color_vector
    )