<tfoot id='NvvzW'></tfoot>
      1. <i id='NvvzW'><tr id='NvvzW'><dt id='NvvzW'><q id='NvvzW'><span id='NvvzW'><b id='NvvzW'><form id='NvvzW'><ins id='NvvzW'></ins><ul id='NvvzW'></ul><sub id='NvvzW'></sub></form><legend id='NvvzW'></legend><bdo id='NvvzW'><pre id='NvvzW'><center id='NvvzW'></center></pre></bdo></b><th id='NvvzW'></th></span></q></dt></tr></i><div id='NvvzW'><tfoot id='NvvzW'></tfoot><dl id='NvvzW'><fieldset id='NvvzW'></fieldset></dl></div>

          <bdo id='NvvzW'></bdo><ul id='NvvzW'></ul>
      2. <legend id='NvvzW'><style id='NvvzW'><dir id='NvvzW'><q id='NvvzW'></q></dir></style></legend>

        <small id='NvvzW'></small><noframes id='NvvzW'>

        R中的Plot.ly:x轴的不需要的字母排序

        时间:2023-09-30

          <tbody id='dY0iH'></tbody>

      3. <i id='dY0iH'><tr id='dY0iH'><dt id='dY0iH'><q id='dY0iH'><span id='dY0iH'><b id='dY0iH'><form id='dY0iH'><ins id='dY0iH'></ins><ul id='dY0iH'></ul><sub id='dY0iH'></sub></form><legend id='dY0iH'></legend><bdo id='dY0iH'><pre id='dY0iH'><center id='dY0iH'></center></pre></bdo></b><th id='dY0iH'></th></span></q></dt></tr></i><div id='dY0iH'><tfoot id='dY0iH'></tfoot><dl id='dY0iH'><fieldset id='dY0iH'></fieldset></dl></div>

      4. <small id='dY0iH'></small><noframes id='dY0iH'>

          <bdo id='dY0iH'></bdo><ul id='dY0iH'></ul>
          <legend id='dY0iH'><style id='dY0iH'><dir id='dY0iH'><q id='dY0iH'></q></dir></style></legend>
          • <tfoot id='dY0iH'></tfoot>

                • 本文介绍了R中的Plot.ly:x轴的不需要的字母排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我尝试了几个小时,但我无法成功.我的数据框很简单

                  I tried for hours, but I could not succeed. My data frame is simply

                  df <- as.data.frame(matrix(c("g","d","a","b","z",5,4,3,2,1),5,2))
                  
                  library("plotly")
                  p <- plot_ly(data = df,x = ~V1,y = ~V2,type = "scatter",mode = "lines+markers") %>%
                  layout(title = "my title")
                  p
                  

                  所以,这个给我

                  但我不希望 x 轴按字母顺序排序,我只想保持原样并查看递减图.

                  But I don't want x axis to be sorted alphabetically, I just want to keep the order as it is and see a decreasing graph.

                  推荐答案

                  首先,一个矩阵只能保存一个类的数据.因此,您有一个要转换为 data.frame 的字符串矩阵.因为默认情况下 stringAsFactors = TRUE,您的字符矩阵将转换为 factordata.frame,其中两列的级别默认排序.V1 按字母顺序排列,V2 按升序排列.

                  First of all, a matrix can only hold data of one class. Hence you have a matrix of strings that you are converting to a data.frame. Because by default stringAsFactors = TRUE, your character matrix is converted to a data.frame of factor's, where the levels of your two columns are by default sorted. Alphabetically for V1 and in increasing order for V2.

                  如果您不希望直接修改数据以从源头上解决问题 - 正如其他答案中指出的那样,您可以替代地使用 plotlycategoryorder =<layout() 中的/code> 参数,方式如下:

                  If you don't wish to modify the data directly to remedy the issue at the source - as pointed out in the other answers, you can altenatively use plotly's categoryorder = argument inside layout() in the following way:

                  library(plotly)
                  xform <- list(categoryorder = "array",
                                categoryarray = df$V1)
                  
                  plot_ly(data = df,
                          x = ~V1,
                          y = ~V2,
                          type = "scatter",
                          mode = "lines+markers") %>%
                          layout(title = "my title",
                                 xaxis = xform)
                  

                  这篇关于R中的Plot.ly:x轴的不需要的字母排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  1. <small id='mdvN1'></small><noframes id='mdvN1'>

                      <tfoot id='mdvN1'></tfoot>
                        <bdo id='mdvN1'></bdo><ul id='mdvN1'></ul>

                        <legend id='mdvN1'><style id='mdvN1'><dir id='mdvN1'><q id='mdvN1'></q></dir></style></legend>
                      • <i id='mdvN1'><tr id='mdvN1'><dt id='mdvN1'><q id='mdvN1'><span id='mdvN1'><b id='mdvN1'><form id='mdvN1'><ins id='mdvN1'></ins><ul id='mdvN1'></ul><sub id='mdvN1'></sub></form><legend id='mdvN1'></legend><bdo id='mdvN1'><pre id='mdvN1'><center id='mdvN1'></center></pre></bdo></b><th id='mdvN1'></th></span></q></dt></tr></i><div id='mdvN1'><tfoot id='mdvN1'></tfoot><dl id='mdvN1'><fieldset id='mdvN1'></fieldset></dl></div>
                          <tbody id='mdvN1'></tbody>