【问题标题】:R Plotly: add more legend to points from scatter plotR Plotly:为散点图中的点添加更多图例
【发布时间】:2017-01-17 13:02:06
【问题描述】:

我有一个包含以下列的数据框:

x y info1 info2 info3

我正在尝试用 r 绘制数据:

plot_ly(data=df, x=x, y=y, mode="lines+markers", color = info1)

在数据的一个点上传递光标时,有没有办法显示 info2/info3?

编辑:示例

df <- read.table(header = TRUE, text="
y   x   info1   info2
John    1   group1  18.32929
John    10  group1  29
John    100 group1  13
Emily   1   group2  4
Emily   10  group2  10
Emily   100 group2  20")

plot_ly(data=df, x=x, y=y, mode="lines+markers", color = info1)

enter image description here

我希望当我传递一个点时也显示 info2,例如 John 第 1 组 18.32929

【问题讨论】:

    标签: r legend plotly


    【解决方案1】:

    根据documentation 中提到的,您可以通过指定hoverinfo 参数来传递自定义悬停信息:

    df %>%
      plot_ly(x = x, y = y, mode = "lines+markers", color = info1,
              hoverinfo = "text",
              text = paste(info1, info2))
    

    这给出了:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-22
      • 1970-01-01
      • 2020-05-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多