I am trying to plot line charts from two data frames where first columns of both data frames are to be plotted in one frame and so forth. And finally all the plots are to be put under one subplot. But I am getting multiple legends with same symbols. The data frames are-
d1 <- data.frame(x = 1:5,
y = c(2, 3, 4, 1, 5),
z = c(2, 1, 4, 6, 8))
d2 <- data.frame(x = 1:5,
y = c(1, 5, 8, 9, 11),
z = c(3, 5, 8, 13, 11))
The code I am trying to generate the subplot is-
py <-
plot_ly(
x = d1$x,
y = d1$y,
type = "scatter",
mode = "lines",
name = names(d1)[2],
line = list(color = "#56B4E9")
) %>% add_trace(y = d2$y,
name = names(d1)[3],
line = list(color = "#D55E00"))
pz <-
plot_ly(
x = d1$x,
y = d1$z,
type = "scatter",
mode = "lines",
name = names(d1)[2],
line = list(color = "#56B4E9")
) %>% add_trace(y = d2$z,
name = names(d1)[3],
line = list(color = "#D55E00"))
subplot(py, pz)
Is there any way to get rid of the duplicate legends?
Thanks in advance.