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

旧巷老猫 提交于 2019-11-29 15:13:41

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!