Reputation: 372
I have some code that pulls reservoir elevation from an API. I have sorted the data and plotted it. When I plot it in native R it looks fine and how I would expect:
When I plot it using plotly I get the following:
The y axis appears to be jumbled with some initially low values on top? I'd like to fix this and essentially match what is produced with the plot() function. Any help with this would be much appreciated.
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')
Upvotes: 0
Views: 51
Reputation: 372
setting y to y=as.numeric(LakeMeadElevation$Elevation) solved the problem.
Upvotes: 1