Retrieve axis tick information from a plotly figure












1















I'm plotting a heatmap using R plotly:



set.seed(1)
df <- reshape2::melt(matrix(rnorm(100*20),100,20,dimnames = list(paste0("G",1:100),paste0("S",1:20))))

library(plotly)
library(dplyr)
plot_ly(z=c(df$value),x=df$Var2,y=df$Var1,colors=grDevices::colorRamp(c("darkblue","gray","darkred")),type="heatmap",colorbar=list(title="Scaled Value",len=0.4)) %>%
layout(yaxis=list(title=NULL),xaxis=list(tickangle=90,tickvals=10,ticktext="X-Label"))


enter image description here



As you can see, plotly is not showing all y-axis ticks. My question is whether it is possible, and if so how, to retrieve the y-axis tick labels plotly selected to show?



I saved the plot object:



plotly.obj <- plot_ly(z=c(df$value),x=df$Var2,y=df$Var1,colors=grDevices::colorRamp(c("darkblue","gray","darkred")),type="heatmap",colorbar=list(title="Scaled Value",len=0.4)) %>%
layout(yaxis=list(title=NULL),xaxis=list(tickangle=90,tickvals=10,ticktext="X-Label"))


And looked around and it seems that perhaps plotly.obj$x$layoutAttrs should store this information but it doesn't:



> plotly.obj$x$layoutAttrs
$`102ce55fd393e`
$`102ce55fd393e`$yaxis
$`102ce55fd393e`$yaxis$title
NULL


$`102ce55fd393e`$xaxis
$`102ce55fd393e`$xaxis$tickangle
[1] 90

$`102ce55fd393e`$xaxis$tickvals
[1] 10

$`102ce55fd393e`$xaxis$ticktext
[1] "X-Label"


Any idea?










share|improve this question



























    1















    I'm plotting a heatmap using R plotly:



    set.seed(1)
    df <- reshape2::melt(matrix(rnorm(100*20),100,20,dimnames = list(paste0("G",1:100),paste0("S",1:20))))

    library(plotly)
    library(dplyr)
    plot_ly(z=c(df$value),x=df$Var2,y=df$Var1,colors=grDevices::colorRamp(c("darkblue","gray","darkred")),type="heatmap",colorbar=list(title="Scaled Value",len=0.4)) %>%
    layout(yaxis=list(title=NULL),xaxis=list(tickangle=90,tickvals=10,ticktext="X-Label"))


    enter image description here



    As you can see, plotly is not showing all y-axis ticks. My question is whether it is possible, and if so how, to retrieve the y-axis tick labels plotly selected to show?



    I saved the plot object:



    plotly.obj <- plot_ly(z=c(df$value),x=df$Var2,y=df$Var1,colors=grDevices::colorRamp(c("darkblue","gray","darkred")),type="heatmap",colorbar=list(title="Scaled Value",len=0.4)) %>%
    layout(yaxis=list(title=NULL),xaxis=list(tickangle=90,tickvals=10,ticktext="X-Label"))


    And looked around and it seems that perhaps plotly.obj$x$layoutAttrs should store this information but it doesn't:



    > plotly.obj$x$layoutAttrs
    $`102ce55fd393e`
    $`102ce55fd393e`$yaxis
    $`102ce55fd393e`$yaxis$title
    NULL


    $`102ce55fd393e`$xaxis
    $`102ce55fd393e`$xaxis$tickangle
    [1] 90

    $`102ce55fd393e`$xaxis$tickvals
    [1] 10

    $`102ce55fd393e`$xaxis$ticktext
    [1] "X-Label"


    Any idea?










    share|improve this question

























      1












      1








      1








      I'm plotting a heatmap using R plotly:



      set.seed(1)
      df <- reshape2::melt(matrix(rnorm(100*20),100,20,dimnames = list(paste0("G",1:100),paste0("S",1:20))))

      library(plotly)
      library(dplyr)
      plot_ly(z=c(df$value),x=df$Var2,y=df$Var1,colors=grDevices::colorRamp(c("darkblue","gray","darkred")),type="heatmap",colorbar=list(title="Scaled Value",len=0.4)) %>%
      layout(yaxis=list(title=NULL),xaxis=list(tickangle=90,tickvals=10,ticktext="X-Label"))


      enter image description here



      As you can see, plotly is not showing all y-axis ticks. My question is whether it is possible, and if so how, to retrieve the y-axis tick labels plotly selected to show?



      I saved the plot object:



      plotly.obj <- plot_ly(z=c(df$value),x=df$Var2,y=df$Var1,colors=grDevices::colorRamp(c("darkblue","gray","darkred")),type="heatmap",colorbar=list(title="Scaled Value",len=0.4)) %>%
      layout(yaxis=list(title=NULL),xaxis=list(tickangle=90,tickvals=10,ticktext="X-Label"))


      And looked around and it seems that perhaps plotly.obj$x$layoutAttrs should store this information but it doesn't:



      > plotly.obj$x$layoutAttrs
      $`102ce55fd393e`
      $`102ce55fd393e`$yaxis
      $`102ce55fd393e`$yaxis$title
      NULL


      $`102ce55fd393e`$xaxis
      $`102ce55fd393e`$xaxis$tickangle
      [1] 90

      $`102ce55fd393e`$xaxis$tickvals
      [1] 10

      $`102ce55fd393e`$xaxis$ticktext
      [1] "X-Label"


      Any idea?










      share|improve this question














      I'm plotting a heatmap using R plotly:



      set.seed(1)
      df <- reshape2::melt(matrix(rnorm(100*20),100,20,dimnames = list(paste0("G",1:100),paste0("S",1:20))))

      library(plotly)
      library(dplyr)
      plot_ly(z=c(df$value),x=df$Var2,y=df$Var1,colors=grDevices::colorRamp(c("darkblue","gray","darkred")),type="heatmap",colorbar=list(title="Scaled Value",len=0.4)) %>%
      layout(yaxis=list(title=NULL),xaxis=list(tickangle=90,tickvals=10,ticktext="X-Label"))


      enter image description here



      As you can see, plotly is not showing all y-axis ticks. My question is whether it is possible, and if so how, to retrieve the y-axis tick labels plotly selected to show?



      I saved the plot object:



      plotly.obj <- plot_ly(z=c(df$value),x=df$Var2,y=df$Var1,colors=grDevices::colorRamp(c("darkblue","gray","darkred")),type="heatmap",colorbar=list(title="Scaled Value",len=0.4)) %>%
      layout(yaxis=list(title=NULL),xaxis=list(tickangle=90,tickvals=10,ticktext="X-Label"))


      And looked around and it seems that perhaps plotly.obj$x$layoutAttrs should store this information but it doesn't:



      > plotly.obj$x$layoutAttrs
      $`102ce55fd393e`
      $`102ce55fd393e`$yaxis
      $`102ce55fd393e`$yaxis$title
      NULL


      $`102ce55fd393e`$xaxis
      $`102ce55fd393e`$xaxis$tickangle
      [1] 90

      $`102ce55fd393e`$xaxis$tickvals
      [1] 10

      $`102ce55fd393e`$xaxis$ticktext
      [1] "X-Label"


      Any idea?







      r plotly axis-labels






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 13 '18 at 18:57









      dandan

      1,45141045




      1,45141045
























          2 Answers
          2






          active

          oldest

          votes


















          1














          I don't think you can get the ticks, that are finally rendered. But you can get all the levels of the y-axis, that ploty can choose from.



          levels(plotly.obj$x$attrs$`2c4c148651ae`$y)


          The ticks that are finally rendered are dynamically chosen and will adapt, depending on your plot size etc.



          You can also check out the attributes with plotly_json():



          plot_ly(z=c(df$value),x=df$Var2,y=df$Var1,colors=grDevices::colorRamp(c("darkblue","gray","darkred")),type="heatmap",colorbar=list(title="Scaled Value",len=0.4)) %>%
          layout(yaxis=list(title=NULL),xaxis=list(tickangle=90,tickvals=10,ticktext="X-Label")) %>%
          plotly_json()





          share|improve this answer































            0














            I got the answer from a github issue I posted on ropensci/plotly:



            set.seed(1)
            df <- reshape2::melt(matrix(rnorm(100*20),100,20,dimnames = list(paste0("G",1:100),paste0("S",1:20))))

            library(plotly)
            library(dplyr)
            plot_ly(z=c(df$value),x=df$Var2,y=df$Var1,colors=grDevices::colorRamp(c("darkblue","gray","darkred")),type="heatmap",colorbar=list(title="Scaled Value",len=0.4)) %>%
            layout(yaxis=list(title=NULL),xaxis=list(tickangle=90,tickvals=10,ticktext="X-Label")) %>%
            htmlwidgets::onRender(
            "function(el, x) {
            alert(el._fullLayout.yaxis._vals.map(function(i) { return i.text; }));
            }"
            )


            Will pop up a browser window with the tick labels.



            The question now is if this can be saved/piped to an R variable or written to a file so it can be done automatically rather than interactively. That's going to be another post.






            share|improve this answer























              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53287801%2fretrieve-axis-tick-information-from-a-plotly-figure%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              1














              I don't think you can get the ticks, that are finally rendered. But you can get all the levels of the y-axis, that ploty can choose from.



              levels(plotly.obj$x$attrs$`2c4c148651ae`$y)


              The ticks that are finally rendered are dynamically chosen and will adapt, depending on your plot size etc.



              You can also check out the attributes with plotly_json():



              plot_ly(z=c(df$value),x=df$Var2,y=df$Var1,colors=grDevices::colorRamp(c("darkblue","gray","darkred")),type="heatmap",colorbar=list(title="Scaled Value",len=0.4)) %>%
              layout(yaxis=list(title=NULL),xaxis=list(tickangle=90,tickvals=10,ticktext="X-Label")) %>%
              plotly_json()





              share|improve this answer




























                1














                I don't think you can get the ticks, that are finally rendered. But you can get all the levels of the y-axis, that ploty can choose from.



                levels(plotly.obj$x$attrs$`2c4c148651ae`$y)


                The ticks that are finally rendered are dynamically chosen and will adapt, depending on your plot size etc.



                You can also check out the attributes with plotly_json():



                plot_ly(z=c(df$value),x=df$Var2,y=df$Var1,colors=grDevices::colorRamp(c("darkblue","gray","darkred")),type="heatmap",colorbar=list(title="Scaled Value",len=0.4)) %>%
                layout(yaxis=list(title=NULL),xaxis=list(tickangle=90,tickvals=10,ticktext="X-Label")) %>%
                plotly_json()





                share|improve this answer


























                  1












                  1








                  1







                  I don't think you can get the ticks, that are finally rendered. But you can get all the levels of the y-axis, that ploty can choose from.



                  levels(plotly.obj$x$attrs$`2c4c148651ae`$y)


                  The ticks that are finally rendered are dynamically chosen and will adapt, depending on your plot size etc.



                  You can also check out the attributes with plotly_json():



                  plot_ly(z=c(df$value),x=df$Var2,y=df$Var1,colors=grDevices::colorRamp(c("darkblue","gray","darkred")),type="heatmap",colorbar=list(title="Scaled Value",len=0.4)) %>%
                  layout(yaxis=list(title=NULL),xaxis=list(tickangle=90,tickvals=10,ticktext="X-Label")) %>%
                  plotly_json()





                  share|improve this answer













                  I don't think you can get the ticks, that are finally rendered. But you can get all the levels of the y-axis, that ploty can choose from.



                  levels(plotly.obj$x$attrs$`2c4c148651ae`$y)


                  The ticks that are finally rendered are dynamically chosen and will adapt, depending on your plot size etc.



                  You can also check out the attributes with plotly_json():



                  plot_ly(z=c(df$value),x=df$Var2,y=df$Var1,colors=grDevices::colorRamp(c("darkblue","gray","darkred")),type="heatmap",colorbar=list(title="Scaled Value",len=0.4)) %>%
                  layout(yaxis=list(title=NULL),xaxis=list(tickangle=90,tickvals=10,ticktext="X-Label")) %>%
                  plotly_json()






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 14 '18 at 8:31









                  SeGaSeGa

                  4,1563834




                  4,1563834

























                      0














                      I got the answer from a github issue I posted on ropensci/plotly:



                      set.seed(1)
                      df <- reshape2::melt(matrix(rnorm(100*20),100,20,dimnames = list(paste0("G",1:100),paste0("S",1:20))))

                      library(plotly)
                      library(dplyr)
                      plot_ly(z=c(df$value),x=df$Var2,y=df$Var1,colors=grDevices::colorRamp(c("darkblue","gray","darkred")),type="heatmap",colorbar=list(title="Scaled Value",len=0.4)) %>%
                      layout(yaxis=list(title=NULL),xaxis=list(tickangle=90,tickvals=10,ticktext="X-Label")) %>%
                      htmlwidgets::onRender(
                      "function(el, x) {
                      alert(el._fullLayout.yaxis._vals.map(function(i) { return i.text; }));
                      }"
                      )


                      Will pop up a browser window with the tick labels.



                      The question now is if this can be saved/piped to an R variable or written to a file so it can be done automatically rather than interactively. That's going to be another post.






                      share|improve this answer




























                        0














                        I got the answer from a github issue I posted on ropensci/plotly:



                        set.seed(1)
                        df <- reshape2::melt(matrix(rnorm(100*20),100,20,dimnames = list(paste0("G",1:100),paste0("S",1:20))))

                        library(plotly)
                        library(dplyr)
                        plot_ly(z=c(df$value),x=df$Var2,y=df$Var1,colors=grDevices::colorRamp(c("darkblue","gray","darkred")),type="heatmap",colorbar=list(title="Scaled Value",len=0.4)) %>%
                        layout(yaxis=list(title=NULL),xaxis=list(tickangle=90,tickvals=10,ticktext="X-Label")) %>%
                        htmlwidgets::onRender(
                        "function(el, x) {
                        alert(el._fullLayout.yaxis._vals.map(function(i) { return i.text; }));
                        }"
                        )


                        Will pop up a browser window with the tick labels.



                        The question now is if this can be saved/piped to an R variable or written to a file so it can be done automatically rather than interactively. That's going to be another post.






                        share|improve this answer


























                          0












                          0








                          0







                          I got the answer from a github issue I posted on ropensci/plotly:



                          set.seed(1)
                          df <- reshape2::melt(matrix(rnorm(100*20),100,20,dimnames = list(paste0("G",1:100),paste0("S",1:20))))

                          library(plotly)
                          library(dplyr)
                          plot_ly(z=c(df$value),x=df$Var2,y=df$Var1,colors=grDevices::colorRamp(c("darkblue","gray","darkred")),type="heatmap",colorbar=list(title="Scaled Value",len=0.4)) %>%
                          layout(yaxis=list(title=NULL),xaxis=list(tickangle=90,tickvals=10,ticktext="X-Label")) %>%
                          htmlwidgets::onRender(
                          "function(el, x) {
                          alert(el._fullLayout.yaxis._vals.map(function(i) { return i.text; }));
                          }"
                          )


                          Will pop up a browser window with the tick labels.



                          The question now is if this can be saved/piped to an R variable or written to a file so it can be done automatically rather than interactively. That's going to be another post.






                          share|improve this answer













                          I got the answer from a github issue I posted on ropensci/plotly:



                          set.seed(1)
                          df <- reshape2::melt(matrix(rnorm(100*20),100,20,dimnames = list(paste0("G",1:100),paste0("S",1:20))))

                          library(plotly)
                          library(dplyr)
                          plot_ly(z=c(df$value),x=df$Var2,y=df$Var1,colors=grDevices::colorRamp(c("darkblue","gray","darkred")),type="heatmap",colorbar=list(title="Scaled Value",len=0.4)) %>%
                          layout(yaxis=list(title=NULL),xaxis=list(tickangle=90,tickvals=10,ticktext="X-Label")) %>%
                          htmlwidgets::onRender(
                          "function(el, x) {
                          alert(el._fullLayout.yaxis._vals.map(function(i) { return i.text; }));
                          }"
                          )


                          Will pop up a browser window with the tick labels.



                          The question now is if this can be saved/piped to an R variable or written to a file so it can be done automatically rather than interactively. That's going to be another post.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 16 '18 at 0:57









                          dandan

                          1,45141045




                          1,45141045






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53287801%2fretrieve-axis-tick-information-from-a-plotly-figure%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Bressuire

                              Vorschmack

                              Quarantine