我有一些代码可以从API中提取储层高度。我已经对数据进行了排序并绘制了图表。当我在本机R中绘制它时,它看起来很好,并且我期望如何:
当我使用plotly绘制时,得到以下信息:
y轴似乎杂乱无章,顶部有些初始值较低?我想解决这个问题,并基本上匹配使用plot()函数产生的结果。任何帮助,将不胜感激。
library("rjson")
library('jsonlite')
library('plotly')
CurrentDate = format(Sys.Date(), "%m-%d-%Y")
StartDate = "1850-01-01"
EndDate = CurrentDate
urlWithoutStart =
paste("https://water.usbr.gov/api/web/app.php/api/series?
sites=hdmlc¶meters=Day.Inst.ReservoirElevation.feet,",
"Day.Sum.ReservoirRelease-
Powerplant.af,Day.Avg.ReservoirRelease-
Powerplant.cfs,Day.Inst.ReservoirStorage.af&",
"start=",sep="")
urlWithoutEnd = paste(urlWithoutStart,StartDate,"&end=",sep="")
urlFull = paste(urlWithoutEnd,EndDate,"&format=json",sep="")
LakeMeadAllData = fromJSON(urlFull)
LakeMeadElevation = as.data.frame(LakeMeadAllData[[1]][[18]][[2]][[1]]
[[1]])
LakeMeadElevation$datetime = as.Date(LakeMeadElevation$datetime)
names(LakeMeadElevation) = c("Date","Elevation","Flag")
LakeMeadElevation <- LakeMeadElevation[order(LakeMeadElevation$Date),]
plot_ly(LakeMeadElevation,x=as.Date(LakeMeadElevation$Date),y=
LakeMeadElevation$Elevation,type = 'scatter',mode="line")
plot(LakeMeadElevation$Date,LakeMeadElevation$Elevation,type='l')
答案 0 :(得分:1)
将y设置为y = as.numeric(LakeMeadElevation $ Elevation)解决了该问题。