使用layout()时,plotty r无法绘制

时间:2018-10-30 06:01:28

标签: r dataframe plot plotly line-plot

我必须绘制一些数据。但是当我使用布局时,我无法在图形中得到任何东西。如果将其删除,则会绘制出已绘制图形但已排序的轴。我不希望已排序的轴。

library(readxl)
library(plotly)
print("OK")
data_ = read_excel(path="Sample data.xlsx")
data_ = as.data.frame(data_)
Dates = c('Dec-17','Jan-18','Feb-18','Mar-18','Apr-18','May-18','Jun-18','Jul-18','Aug-18')

Dates_tb = as.data.frame(table(unlist(Dates)))

data_[3] = Dates_tb
KMS = data_[,1]
ax <- list(
  type = "category",
  categoryarray = Dates,
  categoryorder = "array",
  showgrid = TRUE,
  showline = TRUE,
  autorange = TRUE,
  showticklabels = TRUE,
  ticks = "outside",
  tickangle = 0
)

ay <- list(
 range = c(0,20000),
  dtick = 5000,
  showgrid = TRUE,
  showline = TRUE,
  autorange = FALSE,
  showticklabels = TRUE,
  ticks = "outside",
  tickangle = 0
)

plot_ly(data_,x = ~Dates, y = ~KMS,
         type = "scatter",
         mode = 'lines')%>%
layout(xaxis = ax, yaxis = ay)

如果我移除layout(xaxis = ax, yaxis = ay),我会gt不规则图。如何获取未排序轴的正确图。

0 个答案:

没有答案