[英]plotly in R : feeding add_trace with data from a list() object
I have data that is already stored in a list object. 我有已经存储在列表对象中的数据。 I have several lines to draw one one top of the other.
我有几条线可以画一条线。 I would like to plot them using plotly WITHOUT converting the data into a data frame.
我想使用plotly进行绘制,而无需将数据转换为数据帧。 In the code below, the first line draws fine, but the additional lines do not draw with add_trace() :
在下面的代码中,第一行可以很好地绘制,但其他行则不能使用add_trace()进行绘制:
library(plotly)
d1 = list(x=c(1,2,3,4),y=c(1,2,3,4))
d2 = list(x=c(1,2,3,4),y=c(1,2,3,4)+2)
p<-plot_ly(d1,x=x,y=y)
p<-add_trace(d2,x=x,y=y)
p
giving the error 给出错误
Error in eval(expr, envir, enclos) : object 'x' not found
any ideas? 有任何想法吗? thanks
谢谢
PS : by the way I also find it quite strange that plot_ly does not work without x=x, y=y. PS:顺便说一句,我也很奇怪,没有x = x,y = y,plot_ly无法工作。 I know data is stored like that internally in plotly .
我知道数据是像这样在内部存储的。
You could try: 您可以尝试:
d1 = list(x=c(1,2,3,4),y=c(1,2,3,4))
d2 = list(x=c(1,2,3,4),y=c(1,2,3,4)+2)
p<-plot_ly(d1,x=x,y=y) %>% add_trace(x=d2[[1]], y=d2[[2]])
p
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.