Multiple plots in the same axis in plotly












1














I'm trying to draw plots using the plotly where all of them share the same axis.
This is one dataset



  X variable       value
1 1 SH 0.002814895
2 1 VH 0.002591173
3 1 SS 0.002599700
4 1 HCG 0.002810790


and this is its plotly graph



plot_ly(rr1, x=~variable, y=~value, type = 'scatter', marker=list(size=10, color='rgba(255,182,193,0.9)', 
line=list(color='rgba(152,0,0,0.8)', width = 2)), name = "Character and Degree")%>%
layout(title = "Graph", font = list(family = "Arial Black"),yaxis=list(zerolinecolor = toRGB("red"),
gridcolor = "rgb(190,190,190)"), xaxis=list(gridcolor = "rgb(190,190,190)")) %>%
layout(plot_bgcolor='rgb(230, 230, 230)',paper_bgcolor='rgb(220, 220, 220)',
font = list(color = 'rgb(100,100,100)'))


enter image description here



and this is the other dataset



   X variable       value
1 1 SH 0.000982607
2 1 VH 0.000917569
3 1 SS 0.000911039
4 1 HCG 0.000971009


and this is its plot



     plot_ly(rr2, x=~variable, y=~value, type = 'scatter', marker=list(size=10, color='rgba(38,182,193,0.9)', 

line=list(color='rgba(75,0,0,0.8)', width = 2)), name = "Character and Degree")%>%
layout(title = "Graph", font = list(family = "Arial Black"),yaxis=list(zerolinecolor = toRGB("red"),
gridcolor = "rgb(190,190,190)"), xaxis=list(gridcolor = "rgb(190,190,190)")) %>%
layout(plot_bgcolor='rgb(230, 230, 230)',paper_bgcolor='rgb(220, 220, 220)',
font = list(color = 'rgb(100,100,100)'))


enter image description here



I want these two graphs to share the same axis leaving the colours as it is.










share|improve this question





























    1














    I'm trying to draw plots using the plotly where all of them share the same axis.
    This is one dataset



      X variable       value
    1 1 SH 0.002814895
    2 1 VH 0.002591173
    3 1 SS 0.002599700
    4 1 HCG 0.002810790


    and this is its plotly graph



    plot_ly(rr1, x=~variable, y=~value, type = 'scatter', marker=list(size=10, color='rgba(255,182,193,0.9)', 
    line=list(color='rgba(152,0,0,0.8)', width = 2)), name = "Character and Degree")%>%
    layout(title = "Graph", font = list(family = "Arial Black"),yaxis=list(zerolinecolor = toRGB("red"),
    gridcolor = "rgb(190,190,190)"), xaxis=list(gridcolor = "rgb(190,190,190)")) %>%
    layout(plot_bgcolor='rgb(230, 230, 230)',paper_bgcolor='rgb(220, 220, 220)',
    font = list(color = 'rgb(100,100,100)'))


    enter image description here



    and this is the other dataset



       X variable       value
    1 1 SH 0.000982607
    2 1 VH 0.000917569
    3 1 SS 0.000911039
    4 1 HCG 0.000971009


    and this is its plot



         plot_ly(rr2, x=~variable, y=~value, type = 'scatter', marker=list(size=10, color='rgba(38,182,193,0.9)', 

    line=list(color='rgba(75,0,0,0.8)', width = 2)), name = "Character and Degree")%>%
    layout(title = "Graph", font = list(family = "Arial Black"),yaxis=list(zerolinecolor = toRGB("red"),
    gridcolor = "rgb(190,190,190)"), xaxis=list(gridcolor = "rgb(190,190,190)")) %>%
    layout(plot_bgcolor='rgb(230, 230, 230)',paper_bgcolor='rgb(220, 220, 220)',
    font = list(color = 'rgb(100,100,100)'))


    enter image description here



    I want these two graphs to share the same axis leaving the colours as it is.










    share|improve this question



























      1












      1








      1







      I'm trying to draw plots using the plotly where all of them share the same axis.
      This is one dataset



        X variable       value
      1 1 SH 0.002814895
      2 1 VH 0.002591173
      3 1 SS 0.002599700
      4 1 HCG 0.002810790


      and this is its plotly graph



      plot_ly(rr1, x=~variable, y=~value, type = 'scatter', marker=list(size=10, color='rgba(255,182,193,0.9)', 
      line=list(color='rgba(152,0,0,0.8)', width = 2)), name = "Character and Degree")%>%
      layout(title = "Graph", font = list(family = "Arial Black"),yaxis=list(zerolinecolor = toRGB("red"),
      gridcolor = "rgb(190,190,190)"), xaxis=list(gridcolor = "rgb(190,190,190)")) %>%
      layout(plot_bgcolor='rgb(230, 230, 230)',paper_bgcolor='rgb(220, 220, 220)',
      font = list(color = 'rgb(100,100,100)'))


      enter image description here



      and this is the other dataset



         X variable       value
      1 1 SH 0.000982607
      2 1 VH 0.000917569
      3 1 SS 0.000911039
      4 1 HCG 0.000971009


      and this is its plot



           plot_ly(rr2, x=~variable, y=~value, type = 'scatter', marker=list(size=10, color='rgba(38,182,193,0.9)', 

      line=list(color='rgba(75,0,0,0.8)', width = 2)), name = "Character and Degree")%>%
      layout(title = "Graph", font = list(family = "Arial Black"),yaxis=list(zerolinecolor = toRGB("red"),
      gridcolor = "rgb(190,190,190)"), xaxis=list(gridcolor = "rgb(190,190,190)")) %>%
      layout(plot_bgcolor='rgb(230, 230, 230)',paper_bgcolor='rgb(220, 220, 220)',
      font = list(color = 'rgb(100,100,100)'))


      enter image description here



      I want these two graphs to share the same axis leaving the colours as it is.










      share|improve this question















      I'm trying to draw plots using the plotly where all of them share the same axis.
      This is one dataset



        X variable       value
      1 1 SH 0.002814895
      2 1 VH 0.002591173
      3 1 SS 0.002599700
      4 1 HCG 0.002810790


      and this is its plotly graph



      plot_ly(rr1, x=~variable, y=~value, type = 'scatter', marker=list(size=10, color='rgba(255,182,193,0.9)', 
      line=list(color='rgba(152,0,0,0.8)', width = 2)), name = "Character and Degree")%>%
      layout(title = "Graph", font = list(family = "Arial Black"),yaxis=list(zerolinecolor = toRGB("red"),
      gridcolor = "rgb(190,190,190)"), xaxis=list(gridcolor = "rgb(190,190,190)")) %>%
      layout(plot_bgcolor='rgb(230, 230, 230)',paper_bgcolor='rgb(220, 220, 220)',
      font = list(color = 'rgb(100,100,100)'))


      enter image description here



      and this is the other dataset



         X variable       value
      1 1 SH 0.000982607
      2 1 VH 0.000917569
      3 1 SS 0.000911039
      4 1 HCG 0.000971009


      and this is its plot



           plot_ly(rr2, x=~variable, y=~value, type = 'scatter', marker=list(size=10, color='rgba(38,182,193,0.9)', 

      line=list(color='rgba(75,0,0,0.8)', width = 2)), name = "Character and Degree")%>%
      layout(title = "Graph", font = list(family = "Arial Black"),yaxis=list(zerolinecolor = toRGB("red"),
      gridcolor = "rgb(190,190,190)"), xaxis=list(gridcolor = "rgb(190,190,190)")) %>%
      layout(plot_bgcolor='rgb(230, 230, 230)',paper_bgcolor='rgb(220, 220, 220)',
      font = list(color = 'rgb(100,100,100)'))


      enter image description here



      I want these two graphs to share the same axis leaving the colours as it is.







      r plotly r-plotly






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 23 '18 at 7:32









      Stéphane Laurent

      12.5k65392




      12.5k65392










      asked Nov 23 '18 at 5:50









      Ayesha Perera

      276




      276
























          1 Answer
          1






          active

          oldest

          votes


















          1














          You can merge the two dataframes and use two add_markers, one for each value column:



          df1 <- read.table(text="X variable       value
          1 1 SH 0.002814895
          2 1 VH 0.002591173
          3 1 SS 0.002599700
          4 1 HCG 0.002810790", header=TRUE)

          df2 <- read.table(text=" X variable value
          1 1 SH 0.000982607
          2 1 VH 0.000917569
          3 1 SS 0.000911039
          4 1 HCG 0.000971009", header=TRUE)

          df12 <- merge(df1, df2, by=c("X","variable"))

          library(plotly)

          plot_ly(df12, x=~variable) %>%
          add_markers(y=~value.x, type = 'scatter') %>%
          add_markers(y=~value.y, type = 'scatter')


          But the y-axis title and the legends are not nice:



          enter image description here



          So, modify them:



          ax <- list(
          title = "Value",
          titlefont = list(
          family = "Arial, sans-serif",
          size = 18,
          color = "Red"
          ),
          showticklabels = TRUE
          )

          plot_ly(df12, x=~variable) %>%
          add_markers(y=~value.x, type = 'scatter', name="value1") %>%
          add_markers(y=~value.y, type = 'scatter', name="value2") %>%
          layout(yaxis=ax)


          enter image description here






          share|improve this answer





















          • Thank you. Is there a way to change the shape and the color of the dots and add lines around the dot
            – Ayesha Perera
            Nov 23 '18 at 7:46










          • @AyeshaPerera You're welcome. Look at here for the borders around the dots and the color. I have not found for the shape yet.
            – Stéphane Laurent
            Nov 23 '18 at 7:52










          • Here for the shapes.
            – Stéphane Laurent
            Nov 23 '18 at 7:54










          • @ Stéphane Laurent Thank you very much for the complete answer
            – Ayesha Perera
            Nov 23 '18 at 7:58











          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%2f53441252%2fmultiple-plots-in-the-same-axis-in-plotly%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









          1














          You can merge the two dataframes and use two add_markers, one for each value column:



          df1 <- read.table(text="X variable       value
          1 1 SH 0.002814895
          2 1 VH 0.002591173
          3 1 SS 0.002599700
          4 1 HCG 0.002810790", header=TRUE)

          df2 <- read.table(text=" X variable value
          1 1 SH 0.000982607
          2 1 VH 0.000917569
          3 1 SS 0.000911039
          4 1 HCG 0.000971009", header=TRUE)

          df12 <- merge(df1, df2, by=c("X","variable"))

          library(plotly)

          plot_ly(df12, x=~variable) %>%
          add_markers(y=~value.x, type = 'scatter') %>%
          add_markers(y=~value.y, type = 'scatter')


          But the y-axis title and the legends are not nice:



          enter image description here



          So, modify them:



          ax <- list(
          title = "Value",
          titlefont = list(
          family = "Arial, sans-serif",
          size = 18,
          color = "Red"
          ),
          showticklabels = TRUE
          )

          plot_ly(df12, x=~variable) %>%
          add_markers(y=~value.x, type = 'scatter', name="value1") %>%
          add_markers(y=~value.y, type = 'scatter', name="value2") %>%
          layout(yaxis=ax)


          enter image description here






          share|improve this answer





















          • Thank you. Is there a way to change the shape and the color of the dots and add lines around the dot
            – Ayesha Perera
            Nov 23 '18 at 7:46










          • @AyeshaPerera You're welcome. Look at here for the borders around the dots and the color. I have not found for the shape yet.
            – Stéphane Laurent
            Nov 23 '18 at 7:52










          • Here for the shapes.
            – Stéphane Laurent
            Nov 23 '18 at 7:54










          • @ Stéphane Laurent Thank you very much for the complete answer
            – Ayesha Perera
            Nov 23 '18 at 7:58
















          1














          You can merge the two dataframes and use two add_markers, one for each value column:



          df1 <- read.table(text="X variable       value
          1 1 SH 0.002814895
          2 1 VH 0.002591173
          3 1 SS 0.002599700
          4 1 HCG 0.002810790", header=TRUE)

          df2 <- read.table(text=" X variable value
          1 1 SH 0.000982607
          2 1 VH 0.000917569
          3 1 SS 0.000911039
          4 1 HCG 0.000971009", header=TRUE)

          df12 <- merge(df1, df2, by=c("X","variable"))

          library(plotly)

          plot_ly(df12, x=~variable) %>%
          add_markers(y=~value.x, type = 'scatter') %>%
          add_markers(y=~value.y, type = 'scatter')


          But the y-axis title and the legends are not nice:



          enter image description here



          So, modify them:



          ax <- list(
          title = "Value",
          titlefont = list(
          family = "Arial, sans-serif",
          size = 18,
          color = "Red"
          ),
          showticklabels = TRUE
          )

          plot_ly(df12, x=~variable) %>%
          add_markers(y=~value.x, type = 'scatter', name="value1") %>%
          add_markers(y=~value.y, type = 'scatter', name="value2") %>%
          layout(yaxis=ax)


          enter image description here






          share|improve this answer





















          • Thank you. Is there a way to change the shape and the color of the dots and add lines around the dot
            – Ayesha Perera
            Nov 23 '18 at 7:46










          • @AyeshaPerera You're welcome. Look at here for the borders around the dots and the color. I have not found for the shape yet.
            – Stéphane Laurent
            Nov 23 '18 at 7:52










          • Here for the shapes.
            – Stéphane Laurent
            Nov 23 '18 at 7:54










          • @ Stéphane Laurent Thank you very much for the complete answer
            – Ayesha Perera
            Nov 23 '18 at 7:58














          1












          1








          1






          You can merge the two dataframes and use two add_markers, one for each value column:



          df1 <- read.table(text="X variable       value
          1 1 SH 0.002814895
          2 1 VH 0.002591173
          3 1 SS 0.002599700
          4 1 HCG 0.002810790", header=TRUE)

          df2 <- read.table(text=" X variable value
          1 1 SH 0.000982607
          2 1 VH 0.000917569
          3 1 SS 0.000911039
          4 1 HCG 0.000971009", header=TRUE)

          df12 <- merge(df1, df2, by=c("X","variable"))

          library(plotly)

          plot_ly(df12, x=~variable) %>%
          add_markers(y=~value.x, type = 'scatter') %>%
          add_markers(y=~value.y, type = 'scatter')


          But the y-axis title and the legends are not nice:



          enter image description here



          So, modify them:



          ax <- list(
          title = "Value",
          titlefont = list(
          family = "Arial, sans-serif",
          size = 18,
          color = "Red"
          ),
          showticklabels = TRUE
          )

          plot_ly(df12, x=~variable) %>%
          add_markers(y=~value.x, type = 'scatter', name="value1") %>%
          add_markers(y=~value.y, type = 'scatter', name="value2") %>%
          layout(yaxis=ax)


          enter image description here






          share|improve this answer












          You can merge the two dataframes and use two add_markers, one for each value column:



          df1 <- read.table(text="X variable       value
          1 1 SH 0.002814895
          2 1 VH 0.002591173
          3 1 SS 0.002599700
          4 1 HCG 0.002810790", header=TRUE)

          df2 <- read.table(text=" X variable value
          1 1 SH 0.000982607
          2 1 VH 0.000917569
          3 1 SS 0.000911039
          4 1 HCG 0.000971009", header=TRUE)

          df12 <- merge(df1, df2, by=c("X","variable"))

          library(plotly)

          plot_ly(df12, x=~variable) %>%
          add_markers(y=~value.x, type = 'scatter') %>%
          add_markers(y=~value.y, type = 'scatter')


          But the y-axis title and the legends are not nice:



          enter image description here



          So, modify them:



          ax <- list(
          title = "Value",
          titlefont = list(
          family = "Arial, sans-serif",
          size = 18,
          color = "Red"
          ),
          showticklabels = TRUE
          )

          plot_ly(df12, x=~variable) %>%
          add_markers(y=~value.x, type = 'scatter', name="value1") %>%
          add_markers(y=~value.y, type = 'scatter', name="value2") %>%
          layout(yaxis=ax)


          enter image description here







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 23 '18 at 7:23









          Stéphane Laurent

          12.5k65392




          12.5k65392












          • Thank you. Is there a way to change the shape and the color of the dots and add lines around the dot
            – Ayesha Perera
            Nov 23 '18 at 7:46










          • @AyeshaPerera You're welcome. Look at here for the borders around the dots and the color. I have not found for the shape yet.
            – Stéphane Laurent
            Nov 23 '18 at 7:52










          • Here for the shapes.
            – Stéphane Laurent
            Nov 23 '18 at 7:54










          • @ Stéphane Laurent Thank you very much for the complete answer
            – Ayesha Perera
            Nov 23 '18 at 7:58


















          • Thank you. Is there a way to change the shape and the color of the dots and add lines around the dot
            – Ayesha Perera
            Nov 23 '18 at 7:46










          • @AyeshaPerera You're welcome. Look at here for the borders around the dots and the color. I have not found for the shape yet.
            – Stéphane Laurent
            Nov 23 '18 at 7:52










          • Here for the shapes.
            – Stéphane Laurent
            Nov 23 '18 at 7:54










          • @ Stéphane Laurent Thank you very much for the complete answer
            – Ayesha Perera
            Nov 23 '18 at 7:58
















          Thank you. Is there a way to change the shape and the color of the dots and add lines around the dot
          – Ayesha Perera
          Nov 23 '18 at 7:46




          Thank you. Is there a way to change the shape and the color of the dots and add lines around the dot
          – Ayesha Perera
          Nov 23 '18 at 7:46












          @AyeshaPerera You're welcome. Look at here for the borders around the dots and the color. I have not found for the shape yet.
          – Stéphane Laurent
          Nov 23 '18 at 7:52




          @AyeshaPerera You're welcome. Look at here for the borders around the dots and the color. I have not found for the shape yet.
          – Stéphane Laurent
          Nov 23 '18 at 7:52












          Here for the shapes.
          – Stéphane Laurent
          Nov 23 '18 at 7:54




          Here for the shapes.
          – Stéphane Laurent
          Nov 23 '18 at 7:54












          @ Stéphane Laurent Thank you very much for the complete answer
          – Ayesha Perera
          Nov 23 '18 at 7:58




          @ Stéphane Laurent Thank you very much for the complete answer
          – Ayesha Perera
          Nov 23 '18 at 7:58


















          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%2f53441252%2fmultiple-plots-in-the-same-axis-in-plotly%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

          Basket-ball féminin

          Different font size/position of beamer's navigation symbols template's content depending on regular/plain...

          I want to find a topological embedding $f : X rightarrow Y$ and $g: Y rightarrow X$, yet $X$ is not...