Subplots with a line passing through them











up vote
1
down vote

favorite












I need to pass a through a bunch of violin plots in plotly. So I have come up with this code.



cd = data.frame(id = 1:100, norm = rnorm(100), poi = rpois(100, 1), exp 
= rexp(100,1))
cd = melt(cd, id= "id")
p1 = plot_ly(cd, x=~variable, y=~value, type = 'violin', box =
list(visible =T), meanline = list(visible = T))%>%
layout(annotations = list(text = sprintf("Seeds=10, Coupons=5", 1:10),
font = list(size=16), xanchor = "center", xref = "paper", yref =
"paper", yanchor = "top", showarrow = F, y =1, x=0.5))

ad = data.frame(id = 1:100, norm = rnorm(100), poi = rpois(100, 1), exp
= rexp(100,1))
ad = melt(ad, id= "id")
p2 = plot_ly(ad, x=~variable, y=~value, type = 'violin', box =
list(visible =T), meanline = list(visible = T))%>%
layout(annotations = list(text = sprintf("Seeds=20, Coupons=5", 1:10),
font = list(size=16), xanchor = "center", xref = "paper", yref =
"paper", yanchor = "top", showarrow = F, y =1, x=0.5))
subplot(p1,p2, shareY = T)


and it gave me this plot
enter image description here



But what I'd love to see is a common line passing through 1.8 cutting all plots
enter image description here



also the 'trace 0' to be replaced with 'cd' and 'trace 1' to be replaced with 'ad'
thank you










share|improve this question


























    up vote
    1
    down vote

    favorite












    I need to pass a through a bunch of violin plots in plotly. So I have come up with this code.



    cd = data.frame(id = 1:100, norm = rnorm(100), poi = rpois(100, 1), exp 
    = rexp(100,1))
    cd = melt(cd, id= "id")
    p1 = plot_ly(cd, x=~variable, y=~value, type = 'violin', box =
    list(visible =T), meanline = list(visible = T))%>%
    layout(annotations = list(text = sprintf("Seeds=10, Coupons=5", 1:10),
    font = list(size=16), xanchor = "center", xref = "paper", yref =
    "paper", yanchor = "top", showarrow = F, y =1, x=0.5))

    ad = data.frame(id = 1:100, norm = rnorm(100), poi = rpois(100, 1), exp
    = rexp(100,1))
    ad = melt(ad, id= "id")
    p2 = plot_ly(ad, x=~variable, y=~value, type = 'violin', box =
    list(visible =T), meanline = list(visible = T))%>%
    layout(annotations = list(text = sprintf("Seeds=20, Coupons=5", 1:10),
    font = list(size=16), xanchor = "center", xref = "paper", yref =
    "paper", yanchor = "top", showarrow = F, y =1, x=0.5))
    subplot(p1,p2, shareY = T)


    and it gave me this plot
    enter image description here



    But what I'd love to see is a common line passing through 1.8 cutting all plots
    enter image description here



    also the 'trace 0' to be replaced with 'cd' and 'trace 1' to be replaced with 'ad'
    thank you










    share|improve this question
























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I need to pass a through a bunch of violin plots in plotly. So I have come up with this code.



      cd = data.frame(id = 1:100, norm = rnorm(100), poi = rpois(100, 1), exp 
      = rexp(100,1))
      cd = melt(cd, id= "id")
      p1 = plot_ly(cd, x=~variable, y=~value, type = 'violin', box =
      list(visible =T), meanline = list(visible = T))%>%
      layout(annotations = list(text = sprintf("Seeds=10, Coupons=5", 1:10),
      font = list(size=16), xanchor = "center", xref = "paper", yref =
      "paper", yanchor = "top", showarrow = F, y =1, x=0.5))

      ad = data.frame(id = 1:100, norm = rnorm(100), poi = rpois(100, 1), exp
      = rexp(100,1))
      ad = melt(ad, id= "id")
      p2 = plot_ly(ad, x=~variable, y=~value, type = 'violin', box =
      list(visible =T), meanline = list(visible = T))%>%
      layout(annotations = list(text = sprintf("Seeds=20, Coupons=5", 1:10),
      font = list(size=16), xanchor = "center", xref = "paper", yref =
      "paper", yanchor = "top", showarrow = F, y =1, x=0.5))
      subplot(p1,p2, shareY = T)


      and it gave me this plot
      enter image description here



      But what I'd love to see is a common line passing through 1.8 cutting all plots
      enter image description here



      also the 'trace 0' to be replaced with 'cd' and 'trace 1' to be replaced with 'ad'
      thank you










      share|improve this question













      I need to pass a through a bunch of violin plots in plotly. So I have come up with this code.



      cd = data.frame(id = 1:100, norm = rnorm(100), poi = rpois(100, 1), exp 
      = rexp(100,1))
      cd = melt(cd, id= "id")
      p1 = plot_ly(cd, x=~variable, y=~value, type = 'violin', box =
      list(visible =T), meanline = list(visible = T))%>%
      layout(annotations = list(text = sprintf("Seeds=10, Coupons=5", 1:10),
      font = list(size=16), xanchor = "center", xref = "paper", yref =
      "paper", yanchor = "top", showarrow = F, y =1, x=0.5))

      ad = data.frame(id = 1:100, norm = rnorm(100), poi = rpois(100, 1), exp
      = rexp(100,1))
      ad = melt(ad, id= "id")
      p2 = plot_ly(ad, x=~variable, y=~value, type = 'violin', box =
      list(visible =T), meanline = list(visible = T))%>%
      layout(annotations = list(text = sprintf("Seeds=20, Coupons=5", 1:10),
      font = list(size=16), xanchor = "center", xref = "paper", yref =
      "paper", yanchor = "top", showarrow = F, y =1, x=0.5))
      subplot(p1,p2, shareY = T)


      and it gave me this plot
      enter image description here



      But what I'd love to see is a common line passing through 1.8 cutting all plots
      enter image description here



      also the 'trace 0' to be replaced with 'cd' and 'trace 1' to be replaced with 'ad'
      thank you







      r r-plotly






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 11 at 6:29









      Ayesha Perera

      275




      275
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          You can use add_lines in each plot to add a horizontal line, and by setting name = 'cd' or 'ad' you label the legends:



          library(reshape2)
          library(dplyr)
          library(plotly)
          cd = data.frame(id = 1:100, norm = rnorm(100), poi = rpois(100, 1), exp = rexp(100,1))
          cd = melt(cd, id= "id")
          p1 = plot_ly(cd, x=~variable, y=~value, type = 'violin',name = 'cd', box =
          list(visible =T), meanline = list(visible = T))%>% add_lines(x = ~variable, y =
          rep(1.8,length(cd$id)),showlegend=FALSE)%>%
          layout(annotations = list(text = sprintf("Seeds=10, Coupons=5", 1:10),
          font = list(size=16), xanchor = "center", xref = "paper", yref =
          "paper", yanchor = "top", showarrow = F, y =1, x=0.5))

          ad = data.frame(id = 1:100, norm = rnorm(100), poi = rpois(100, 1), exp =
          rexp(100,1))
          ad = melt(ad, id= "id")
          p2 = plot_ly(ad, x=~variable, y=~value, type = 'violin',name = 'ad',box =
          list(visible =T), meanline = list(visible = T))%>% add_lines(x = ~variable, y =
          rep(1.8,length(ad$id)),showlegend=FALSE)%>%
          layout(annotations = list(text = sprintf("Seeds=20, Coupons=5", 1:10),
          font = list(size=16), xanchor = "center", xref = "paper", yref =
          "paper", yanchor = "top", showarrow = F, y =1, x=0.5))

          vline <- function(x = 0, color = "red") {
          list(
          type = "line",
          y0 = 0,
          y1 = 1,
          yref = "paper",
          x0 = x,
          x1 = x,
          line = list(color = color)
          )
          }

          subplot(p1,p2, shareY = T)





          share|improve this answer





















          • Thanks, It does give the output, but is there a way to make that line continous?
            – Ayesha Perera
            Nov 11 at 7:10










          • Not as far as I know..
            – CIAndrews
            Nov 11 at 7:15










          • Okay, thank you
            – Ayesha Perera
            Nov 11 at 7:32











          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',
          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%2f53246393%2fsubplots-with-a-line-passing-through-them%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote



          accepted










          You can use add_lines in each plot to add a horizontal line, and by setting name = 'cd' or 'ad' you label the legends:



          library(reshape2)
          library(dplyr)
          library(plotly)
          cd = data.frame(id = 1:100, norm = rnorm(100), poi = rpois(100, 1), exp = rexp(100,1))
          cd = melt(cd, id= "id")
          p1 = plot_ly(cd, x=~variable, y=~value, type = 'violin',name = 'cd', box =
          list(visible =T), meanline = list(visible = T))%>% add_lines(x = ~variable, y =
          rep(1.8,length(cd$id)),showlegend=FALSE)%>%
          layout(annotations = list(text = sprintf("Seeds=10, Coupons=5", 1:10),
          font = list(size=16), xanchor = "center", xref = "paper", yref =
          "paper", yanchor = "top", showarrow = F, y =1, x=0.5))

          ad = data.frame(id = 1:100, norm = rnorm(100), poi = rpois(100, 1), exp =
          rexp(100,1))
          ad = melt(ad, id= "id")
          p2 = plot_ly(ad, x=~variable, y=~value, type = 'violin',name = 'ad',box =
          list(visible =T), meanline = list(visible = T))%>% add_lines(x = ~variable, y =
          rep(1.8,length(ad$id)),showlegend=FALSE)%>%
          layout(annotations = list(text = sprintf("Seeds=20, Coupons=5", 1:10),
          font = list(size=16), xanchor = "center", xref = "paper", yref =
          "paper", yanchor = "top", showarrow = F, y =1, x=0.5))

          vline <- function(x = 0, color = "red") {
          list(
          type = "line",
          y0 = 0,
          y1 = 1,
          yref = "paper",
          x0 = x,
          x1 = x,
          line = list(color = color)
          )
          }

          subplot(p1,p2, shareY = T)





          share|improve this answer





















          • Thanks, It does give the output, but is there a way to make that line continous?
            – Ayesha Perera
            Nov 11 at 7:10










          • Not as far as I know..
            – CIAndrews
            Nov 11 at 7:15










          • Okay, thank you
            – Ayesha Perera
            Nov 11 at 7:32















          up vote
          1
          down vote



          accepted










          You can use add_lines in each plot to add a horizontal line, and by setting name = 'cd' or 'ad' you label the legends:



          library(reshape2)
          library(dplyr)
          library(plotly)
          cd = data.frame(id = 1:100, norm = rnorm(100), poi = rpois(100, 1), exp = rexp(100,1))
          cd = melt(cd, id= "id")
          p1 = plot_ly(cd, x=~variable, y=~value, type = 'violin',name = 'cd', box =
          list(visible =T), meanline = list(visible = T))%>% add_lines(x = ~variable, y =
          rep(1.8,length(cd$id)),showlegend=FALSE)%>%
          layout(annotations = list(text = sprintf("Seeds=10, Coupons=5", 1:10),
          font = list(size=16), xanchor = "center", xref = "paper", yref =
          "paper", yanchor = "top", showarrow = F, y =1, x=0.5))

          ad = data.frame(id = 1:100, norm = rnorm(100), poi = rpois(100, 1), exp =
          rexp(100,1))
          ad = melt(ad, id= "id")
          p2 = plot_ly(ad, x=~variable, y=~value, type = 'violin',name = 'ad',box =
          list(visible =T), meanline = list(visible = T))%>% add_lines(x = ~variable, y =
          rep(1.8,length(ad$id)),showlegend=FALSE)%>%
          layout(annotations = list(text = sprintf("Seeds=20, Coupons=5", 1:10),
          font = list(size=16), xanchor = "center", xref = "paper", yref =
          "paper", yanchor = "top", showarrow = F, y =1, x=0.5))

          vline <- function(x = 0, color = "red") {
          list(
          type = "line",
          y0 = 0,
          y1 = 1,
          yref = "paper",
          x0 = x,
          x1 = x,
          line = list(color = color)
          )
          }

          subplot(p1,p2, shareY = T)





          share|improve this answer





















          • Thanks, It does give the output, but is there a way to make that line continous?
            – Ayesha Perera
            Nov 11 at 7:10










          • Not as far as I know..
            – CIAndrews
            Nov 11 at 7:15










          • Okay, thank you
            – Ayesha Perera
            Nov 11 at 7:32













          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          You can use add_lines in each plot to add a horizontal line, and by setting name = 'cd' or 'ad' you label the legends:



          library(reshape2)
          library(dplyr)
          library(plotly)
          cd = data.frame(id = 1:100, norm = rnorm(100), poi = rpois(100, 1), exp = rexp(100,1))
          cd = melt(cd, id= "id")
          p1 = plot_ly(cd, x=~variable, y=~value, type = 'violin',name = 'cd', box =
          list(visible =T), meanline = list(visible = T))%>% add_lines(x = ~variable, y =
          rep(1.8,length(cd$id)),showlegend=FALSE)%>%
          layout(annotations = list(text = sprintf("Seeds=10, Coupons=5", 1:10),
          font = list(size=16), xanchor = "center", xref = "paper", yref =
          "paper", yanchor = "top", showarrow = F, y =1, x=0.5))

          ad = data.frame(id = 1:100, norm = rnorm(100), poi = rpois(100, 1), exp =
          rexp(100,1))
          ad = melt(ad, id= "id")
          p2 = plot_ly(ad, x=~variable, y=~value, type = 'violin',name = 'ad',box =
          list(visible =T), meanline = list(visible = T))%>% add_lines(x = ~variable, y =
          rep(1.8,length(ad$id)),showlegend=FALSE)%>%
          layout(annotations = list(text = sprintf("Seeds=20, Coupons=5", 1:10),
          font = list(size=16), xanchor = "center", xref = "paper", yref =
          "paper", yanchor = "top", showarrow = F, y =1, x=0.5))

          vline <- function(x = 0, color = "red") {
          list(
          type = "line",
          y0 = 0,
          y1 = 1,
          yref = "paper",
          x0 = x,
          x1 = x,
          line = list(color = color)
          )
          }

          subplot(p1,p2, shareY = T)





          share|improve this answer












          You can use add_lines in each plot to add a horizontal line, and by setting name = 'cd' or 'ad' you label the legends:



          library(reshape2)
          library(dplyr)
          library(plotly)
          cd = data.frame(id = 1:100, norm = rnorm(100), poi = rpois(100, 1), exp = rexp(100,1))
          cd = melt(cd, id= "id")
          p1 = plot_ly(cd, x=~variable, y=~value, type = 'violin',name = 'cd', box =
          list(visible =T), meanline = list(visible = T))%>% add_lines(x = ~variable, y =
          rep(1.8,length(cd$id)),showlegend=FALSE)%>%
          layout(annotations = list(text = sprintf("Seeds=10, Coupons=5", 1:10),
          font = list(size=16), xanchor = "center", xref = "paper", yref =
          "paper", yanchor = "top", showarrow = F, y =1, x=0.5))

          ad = data.frame(id = 1:100, norm = rnorm(100), poi = rpois(100, 1), exp =
          rexp(100,1))
          ad = melt(ad, id= "id")
          p2 = plot_ly(ad, x=~variable, y=~value, type = 'violin',name = 'ad',box =
          list(visible =T), meanline = list(visible = T))%>% add_lines(x = ~variable, y =
          rep(1.8,length(ad$id)),showlegend=FALSE)%>%
          layout(annotations = list(text = sprintf("Seeds=20, Coupons=5", 1:10),
          font = list(size=16), xanchor = "center", xref = "paper", yref =
          "paper", yanchor = "top", showarrow = F, y =1, x=0.5))

          vline <- function(x = 0, color = "red") {
          list(
          type = "line",
          y0 = 0,
          y1 = 1,
          yref = "paper",
          x0 = x,
          x1 = x,
          line = list(color = color)
          )
          }

          subplot(p1,p2, shareY = T)






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 11 at 6:59









          CIAndrews

          1886




          1886












          • Thanks, It does give the output, but is there a way to make that line continous?
            – Ayesha Perera
            Nov 11 at 7:10










          • Not as far as I know..
            – CIAndrews
            Nov 11 at 7:15










          • Okay, thank you
            – Ayesha Perera
            Nov 11 at 7:32


















          • Thanks, It does give the output, but is there a way to make that line continous?
            – Ayesha Perera
            Nov 11 at 7:10










          • Not as far as I know..
            – CIAndrews
            Nov 11 at 7:15










          • Okay, thank you
            – Ayesha Perera
            Nov 11 at 7:32
















          Thanks, It does give the output, but is there a way to make that line continous?
          – Ayesha Perera
          Nov 11 at 7:10




          Thanks, It does give the output, but is there a way to make that line continous?
          – Ayesha Perera
          Nov 11 at 7:10












          Not as far as I know..
          – CIAndrews
          Nov 11 at 7:15




          Not as far as I know..
          – CIAndrews
          Nov 11 at 7:15












          Okay, thank you
          – Ayesha Perera
          Nov 11 at 7:32




          Okay, thank you
          – Ayesha Perera
          Nov 11 at 7:32


















          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.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • 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%2f53246393%2fsubplots-with-a-line-passing-through-them%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

          The Sandy Post

          Danny Elfman

          Pages that link to "Head v. Amoskeag Manufacturing Co."