简体   繁体   中英

plot 3d scatterplot in R with x axis as time

I have data with time in H:M:S format, lattitude and longitude. I need to plot a 3D scatterplot with them. The time is not at regular intervals.

I have tried using plotly with following code:

library(readxl)
bus1<-read_excel('example.xlsx',col_names=TRUE)
x<- as.POSIXct(bus1$Time,format = '%H:%M:%S')
y<-bus1$Lattitude
z<-bus1$Longitude
library(plotly)

plot_ly(x=x , y=y , z=z ,type="scatter3d",mode="lines",
       colors = c('#BF382A', '#0C4B8E')) %>%
       add_markers() %>%
       layout(scene = list(xaxis = list(title = 'Time'),
                        yaxis = list(title = 'Lattitude'),
                        zaxis = list(title = 'Longitude')))

This is giving me some weird plot with very few data points.

Output for this: 为此的输出

Your plotly syntax looks problematic. The tilde operator ~ is often needed. For example:

plot_ly(~z, type="scatter")

You should check out this free tutorial by DataCamp . I found its exercises to be helpful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM