1
votes

I have a dataframe with the following columns:

x y info1 info2 info3

I am trying to plot the data with r plotly:

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

Is there a way to display info2/info3 when passing the cursor on one point of the data?

EDIT: Example

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

I would like when I pass on a point to also display the info2 such as John group1 18.32929

1

1 Answers

1
votes

As per mentionned in the documentation, you can pass custom hover info by specifying the hoverinfo parameter:

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

Which gives:

enter image description here