【问题标题】:How to paste items of a list in aplotly title?如何将列表中的项目粘贴到标题中?
【发布时间】:2020-09-24 07:48:53
【问题描述】:

您好,我如何将多个项目粘贴到一个情节标题中。这是我的代码:

    timestep = 2
    lst_raitings_hy =  c("BB", "B")

fig_hy <- plot_ly(x = summaries_hy$maturity)
fig_hy <- fig_hy %>% add_trace(y = summaries_hy$mean_yield, name = "Mean", type="scatter", mode="lines+markers", marker=list(color = "rgba(0,100,0,1)", line = list(color = "rgba(0,100,0,1)", shape = "spline")))
fig_hy <- fig_hy %>% add_trace(y = summaries_hy$perc_005, name = "0.5% Percentile", type="scatter", fill='tonexty', fillcolor='rgba(0,70,100,0.5)',mode = 'lines', line = list(color = "transparent", shape = "spline"))
fig_hy <- fig_hy %>% add_trace(y = summaries_hy$perc_05, name = "5% Percentile", type="scatter", fill='tonexty', fillcolor='rgba(0,50,100,0.6)', mode = 'lines', line = list(color = "transparent", shape = "spline"))
fig_hy <- fig_hy %>% add_trace(y = summaries_hy$perc_75, name = "75% Percentile", type="scatter", fill='tonexty', fillcolor='rgba(0,40,100,0.4)', mode = 'lines', line = list(color = "transparent", shape = "spline"))
fig_hy <- fig_hy %>% add_trace(y = summaries_hy$perc_995, name = "99.5% Percentile", type="scatter", fill='tonexty', fillcolor='rgba(0,10,100,0.1)', mode = 'lines', line = list(color = "transparent", shape = "spline"))
fig_hy <- fig_hy %>%    layout(
  title = paste("Worst Case HighYield SpotSpread Curve timestep", timestep, lst_raitings_hy),
  xaxis = list(title = "Maturity"),
  yaxis = list(title = "Spot Spread", tickformat=" .2%")
)
 
fig_hy

现在你可以看到我想在标题中粘贴两个 raiting,但它不起作用。如果我只选择一个,一切都很好。 谢谢!:)

【问题讨论】:

    标签: r r-plotly


    【解决方案1】:

    我假设您对标题的预期输出是:"Worst Case HighYield SpotSpread Curve timestep 2 BB B"。问题是您使用粘贴的方式是将前两个字符串粘贴到具有length =2 的字符串向量lst_raitings_hy。结果是两个字符串:"Worst Case HighYield SpotSpread Curve timestep 2 BB" "Worst Case HighYield SpotSpread Curve timestep 2 B"。为避免这种情况并接收具有上述预期结果的标题的单个字符串,首先将向量 lst_raitings_hy 的元素粘贴在一起并将其与其他字符串组合:

    paste("Worst Case HighYield SpotSpread Curve timestep", timestep, paste(lst_raitings_hy, collapse = " "))
    

    【讨论】:

    • 你成功了!非常感谢! :)
    猜你喜欢
    • 2018-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-29
    相关资源
    最近更新 更多