我已经创建了一个基本的填充图,并且我尝试添加一条平均线:
library(plotly)
week<-c(2,1,3)
pts<-c(10,20,30)
wex<-data.frame(week,pts)
wex <- wex[order(wex$week), ]
plot_ly(x = ~wex$week, y = ~wex$pts, type = 'scatter', mode = 'lines',
fill = 'tozeroy')%>%
add_segments(x = 0, xend = max(wex$week), y = mean(wex$pts), yend =mean(wex$pts) )
但是我得到了一个完整的区域,而不是一行。我猜想它与yend
参数有关,但没有意义,因为它与y
参数相同。
答案 0 :(得分:1)
似乎fill='tozeroy'
被保留用于add_segments()
呼叫。
这有效:
library(plotly)
week<-c(2,1,3)
pts<-c(10,20,30)
wex<-data.frame(week,pts)
wex <- wex[order(wex$week), ]
wex
plot_ly(x = ~wex$week, y = ~wex$pts, type = 'scatter', mode = 'lines',
fill = 'tozeroy')%>%
add_segments(x = 0, xend = max(wex$week), y = mean(wex$pts), yend =mean(wex$pts),fill = 'none' )
我在fill = 'none'
中添加了add_segments()