带有日期时间的R中带有plotly的颜色会影响x轴限制

带有日期时间的R中带有plotly的颜色会影响x轴限制,r,shiny,plotly,R,Shiny,Plotly,在R中使用带有日期时间的plotly和颜色arg,似乎有一个奇怪之处,x轴默认值不能正常工作。它的范围可以追溯到1970年 library(plotly) start <- as.POSIXct("2012-01-15") interval <- 60 end <- start + as.difftime(1, units="days") mydate <- seq(from=start, by=interval*60, to=end) mydf <- da

在R中使用带有日期时间的plotly和
颜色
arg,似乎有一个奇怪之处,x轴默认值不能正常工作。它的范围可以追溯到1970年

library(plotly)

start <- as.POSIXct("2012-01-15")
interval <- 60

end <- start + as.difftime(1, units="days")

mydate <- seq(from=start, by=interval*60, to=end)

mydf <- data.frame(date=mydate, y=rnorm(1:length(mydate)))

p <- plot_ly(data=mydf, x=~date, y=~y, color=~y)
p
library(plotly)

开始这是有益的和工作,谢谢。如果有人能从根本上解决这个问题,我们将把它留到另一天左右。
plot_ly(data=mydf, x=~date, y=~y, color=~y) %>%
  layout(
    xaxis = list(range = c(1326603600, 1326690000)),
    yaxis = list(range = c(-10, 10)))
library(plotly)
start <- as.POSIXct("2012-01-15")
interval <- 60
end <- start + as.difftime(1, units="days")
mydate <- seq(from=start, by=interval*60, to=end)
mydf <- data.frame(date=mydate, y=rnorm(1:length(mydate)))

p <- plot_ly(data=mydf, x=~date, y=~y, color=~y, 
             mode="markers", type="scatter", marker=list(size=15)) %>%
add_trace(data=mydf, x=~date, y=~y, mode="lines", line=list(color="navy"))

# Important: set x-axis type as "category" !
p %>% layout(xaxis=list(type="category", range=list(-.5,(length(mydate)-.5))), 
             margin=list(b=100))