以情节方式更改线条粗细 [英] Change line thickness in plotly

查看:65
本文介绍了以情节方式更改线条粗细的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些数据

theData <- structure(list(matter_date = structure(c(16921, 16940, 16941, 
16944, 16947, 16976, 17013, 16921, 16976, 17013, 16921, 17013, 
16921, 16944, 16947, 16976, 17013, 16944, 17013, 16921, 16921, 
16941, 16976, 17013, 16921, 17013, 16921, 16940, 16976, 17013, 
16921, 16941, 16976, 16921, 16976, 17013, 16921, 16944, 16976, 
17013, 16921, 16940, 16941, 16944, 16947, 16976, 17013), class = "Date"), 
    variable = c("meanOfMeans", "meanOfMeans", "meanOfMeans", 
    "meanOfMeans", "meanOfMeans", "meanOfMeans", "meanOfMeans", 
    "Dude1", "Dude1", "Dude1", "Dude2", "Dude2", "Dude4", "Dude4", 
    "Dude4", "Dude4", "Dude4", "Dude5", "Dude5", "Dude6", "Dude7", 
    "Dude7", "Dude7", "Dude7", "Dude8", "Dude8", "Dude9", "Dude9", 
    "Dude9", "Dude9", "Dude10", "Dude10", "Dude10", "Dude11", 
    "Dude11", "Dude11", "Dude12", "Dude12", "Dude12", "Dude12", 
    "Regression", "Regression", "Regression", "Regression", "Regression", 
    "Regression", "Regression"), value = c(72.767610875949, 90.9392641619622, 
    45.7405729014483, 85.7259119652673, 105, 80.312242735507, 
    81.5089081756173, 62.0696399467241, 59.462122627886, 83.855246493738, 
    103.75, 102.42032111191, 89.9205770857696, 98.1040118882406, 
    105, 88.9856689007873, 94.4812947992748, 59.0737240075614, 
    63.3163826710261, 79.174945478451, 55.7207891785418, 46.0817358331578, 
    81.4596142685542, 77.1262273117138, 60.4308669614855, 61.3321478799418, 
    89.9425197232886, 90.9392641619622, 85.916058394926, 89.1779327977449, 
    59.9003207762254, 45.3994099697388, 68.9847172646122, 46.8048325311855, 
    93.4687872124697, 79.4732085405457, 79.9616170778186, 100, 
    83.9087304793132, 82.3974119746606, 80.565164208156, 80.7257268243583, 
    80.734177488369, 80.7595294804009, 80.7848814724329, 81.0299507287417, 
    81.3426252971356), thickness = c(1, 1, 1, 1, 1, 1, 1, 1, 
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 4, 4, 4, 4, 4, 
    4)), .Names = c("matter_date", "variable", "value", "thickness"
), class = c("data.table", "data.frame"), row.names = c(NA, -47L)
)

并且可以用

    plot_ly(theData, x = ~matter_date, y = ~value, color = ~variable, colors =RColorBrewer::brewer.pal(12, "Set3"), type = "scatter", mode = "lines") %>% 
  layout(
    title = "Realization",
    xaxis = list(rangeslider = list(type = "date")),#,
    yaxis = list(title = "Realization Average%",
                 range = c(0,105)
    )
  )

但我想让粗细栏决定线条的粗细.这可能吗?

but I'd like to make the thickness column determine the thickness of the line. Is this possible?

推荐答案

plot_ly(theData, x = ~matter_date, y = ~value, color = ~variable, colors         
=RColorBrewer::brewer.pal(12, "Set3"), type = "scatter", mode = "lines", 
line=list(width=~thickness)) %>% 
layout(
title = "Realization",
xaxis = list(rangeslider = list(type = "date")),#,
yaxis = list(title = "Realization Average%",
             range = c(0,105)
)

)

我遇到了同样的问题,这是我遇到的解决方案.希望它有帮助:)

I had the same kind of issue and this is the solution I came across. Hope it helps :)

这篇关于以情节方式更改线条粗细的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆