R Plotly: Cannot re-arrange x-axis when axis type is category

后端 未结 1 1559
孤城傲影
孤城傲影 2020-12-19 08:04

I have the following data:

myData <- data.frame(FISCAL_YEAR_WEEK = c(\'2016-09\',\'2016-09\',\'2016-09\',\'2016-09\',\'2016-09\',\'2016-10\',\'2016-10\',\         


        
1条回答
  •  心在旅途
    2020-12-19 08:15

    Until recently, the only way to sort a plot.ly categorical axis was to sort the data of the first categorical trace of the graph (ref: Etienne's answer on plot.ly community site).

    That's changed, and you can achieve the categorical axis sort you desire by setting categoryorder in either of the following manners:

    ax <- list(
      type = "category",
      categoryorder = "category ascending",
      showgrid = TRUE,
      showline = TRUE,
      autorange = TRUE,
      showticklabels = TRUE,
      ticks = "outside",
      tickangle = 0
    )
    

    Or:

    ax <- list(
      type = "category",
      categoryorder = "array",
      categoryarray = sort(unique(myData$FISCAL_YEAR_WEEK)),
      showgrid = TRUE,
      showline = TRUE,
      autorange = TRUE,
      showticklabels = TRUE,
      ticks = "outside",
      tickangle = 0
    )
    

    For more on plot.ly's categorical axis sort, see their reference doc.

    0 讨论(0)
提交回复
热议问题