<!DOCTYPE html> <html lang="en"> <head> <!-- Google Analytics + OutboundLink + Google Adsense --> <script async src="https://www.googletagmanager.com/gtag/js?id=UA-79254642-1"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'UA-79254642-1'); </script> <script> var getOutboundLink = function(url) { gtag('event', 'click', { 'event_category': 'outbound', 'event_label': url, 'transport_type': 'beacon', 'event_callback': function(){document.location = url;} }); } </script> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <script> (adsbygoogle = window.adsbygoogle || []).push({ google_ad_client: "ca-pub-3523953066677938", enable_page_level_ads: true }); </script> <!-- Google Analytics + OutboundLink + Google Adsense --> <meta charset="utf-8"> <title>Connected Scatterplot | the R Graph Gallery</title> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <meta name="description" content="How to build a connected scatterplot with R: from the most basic example to highly customized examples. Focus on ggplot2 and reproducible code"> <meta name="keywords" content="Data,Dataviz,Datavisualization,Javascript,R,ggplot2,tidyverse,area chart"> <meta name="author" content="Yan Holtz"> <link rel="icon" href="img/logo/R_single_small.png"> <meta property="og:title" content="Connected Scatterplot | the R Graph Gallery"> <meta property="og:image" content="img/overview_RGG.png"> <meta property="og:description" content="How to build a connected scatterplot with R: from the most basic example to highly customized examples. Focus on ggplot2 and reproducible code"> <!-- Bootstrap core CSS --> <link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet"> <!-- Custom fonts for this template --> <link href="vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css"> <!-- Custom styles for this template --> <link href="css/agency.css" rel="stylesheet"> <!-- JQUERY --> <script src="vendor/jquery/jquery.min.js"></script> </head> <body id="page-top"> <!-- THIS ALLOWS TO INSERT THE MENU THAT IS STORED IN A MENU.HTML FILE--> <nav class="navbar navbar-expand-lg fixed-top" id="mainNav"></nav> <script> $(function(){ $("#mainNav").load("html_chunk/menu.html"); }); </script> <!-- THIS ALLOWS TO INSERT THE MODAL OF THE MENU THAT IS STORED IN A MENU_MODAL.HTML FILE--> <div id="modal_menu_insertion"> </div> <script> $(function(){ $("#modal_menu_insertion").load("html_chunk/menu_modal.html"); }); </script> <!-- Header --> <header class="masthead" style="padding-top: 150px; padding-bottom: 80px"> <div class="textlanding"> <h1>Connected Scatterplot</h1> <hr class="short_hr"> <br> <ul class="list-inline social-buttons"> <li class="list-inline-item"> <a href="https://twitter.com/R_Graph_Gallery"> <i class="fa fa-twitter"></i> </a> </li> <li class="list-inline-item social-buttons"> <a href="https://github.com/holtzy"> <i class="fa fa-github" style="color: white"></i> </a> </li> <li class="list-inline-item social-buttons"> <a href="https://www.linkedin.com/in/yan-holtz-2477534a/"> <i class="fa fa-linkedin"></i> </a> </li> <li class="list-inline-item social-buttons"> <a href="https://www.yan-holtz.com"> <i class="fa fa-home"></i> </a> </li> </ul> <br><br> <p style="max-width: 700px; margin: auto">Welcome to the <a href="https://www.data-to-viz.com/graph/connectedscatter.html">connected scatterplot</a> section of the gallery. If you want to know more about this kind of chart, visit <a href="https://www.data-to-viz.com/graph/connectedscatter.html">data-to-viz.com</a>. If you're looking for a simple way to implement it in R and <code>ggplot2</code>, pick an example below.</p> </div> </header> <!-- THIS ALLOWS TO INSERT THE ADVERTISEMENT BANNER THAT IS STORED IN A BANNER.HTML FILE--> <div id="position_for_images"> </div> <script> $(function(){ $("#position_for_images").load("html_chunk/images.html"); }); </script> <!-- ======================== PORTFOLIO SECTION ============================ --> <!-- Images must be 480 x 480, resize them with ./script_reformat_img.sh output_name.png --> <section class="bg" id="portfolio" style="padding-top: 10px"> <div class="container"> <div class="mySeryTitle">Note on connected scatterplot</div> <hr> <p>It is of importance to understand that a connected scatterplot is basically an hybrid between a <a href="scatterplot.html">scatterplot</a> and a <a href="line-plot.html">lineplot</a>. Thus, please visit the related section <a href="scatterplot.html">here</a> and <a href="line-plot.html">here</a> to get more examples, since the techniques used are very similar.</p> <p>Please note also that <u>2 types</u> of connected scatterplot exist. The <u>first</u> is simply a lineplot with dots added on top of it. It takes as input 2 numeric variables only. The <u>second</u> shows the relationship between 2 numerical variables across time. It requires 3 numerical variables as input. Confusing? Visit <a href="https://www.data-to-viz.com/graph/connectedscatter.html">data-to-viz</a> to clarify.</p> <br><br> <div class="mySeryTitle">Step by step with <code>ggplot2</code></div> <hr> <p>Pretty straightforward once you understood how to build a <a href="scatterplot.html">scatterplot</a> and a <a href="line-plot.html">lineplot</a>. See the focus on <a href="">annotation</a> that is handy for the second type of connected scatter (see above).</p> <div id="portfolio-items" class="row"> <div class="col-md-4 col-sm-6 portfolio-item"> <a class="portfolio-link" href="connected_scatterplot_ggplot2.html"> <div class="portfolio-hover"> <div class="portfolio-hover-content"> <p>Most basic</p> <hr> <p class="explanation_portfolio">Most basic scatterplot with R and ggplot2</p> </div> </div> <img class="img-fluid imgOfPortfolio" src="img/graph/connected_scatterplot_ggplot21.png" alt=""> </a> </div> <div class="col-md-4 col-sm-6 portfolio-item"> <a class="portfolio-link" href="connected_scatterplot_ggplot2.html"> <div class="portfolio-hover"> <div class="portfolio-hover-content"> <p>Custom appearance</p> <hr> <p class="explanation_portfolio">Classic appearance customization with theme_ipsum and more</p> </div> </div> <img class="img-fluid imgOfPortfolio" src="img/graph/connected_scatterplot_ggplot22.png" alt=""> </a> </div> <div class="col-md-4 col-sm-6 portfolio-item"> <a class="portfolio-link" href="connected_scatterplot_ggplot2.html"> <div class="portfolio-hover"> <div class="portfolio-hover-content"> <p>Connected Scatter for evolution</p> <hr> <p class="explanation_portfolio">Use connected scatterplot with 3 numeric variable to show an evolution.</p> </div> </div> <img class="img-fluid imgOfPortfolio" src="img/graph/connected_scatterplot_ggplot23.png" alt=""> </a> </div> </div> <br><br> <div class="mySeryTitle">Connected scatterplot for <a href="time-series.html">time series</a></div> <hr> <p>Connected scatterplots are often used for <a href="time-series.html">time series</a>. Remember the R graph gallery offers a dedicated section, with heaps of examples. For instance, here is an interactive chart made with the <a href="time-series.html">dygraphs</a> library.</p> <div style="text-align:left"> <a class="btn btn-secondary text-uppercase js-scroll-trigger" href="318-custom-dygraphs-time-series-example.html">Code of this chart</a> <a class="btn btn-secondary text-uppercase js-scroll-trigger" href="time-series.html">Time series section</a> </div> <br> <center><iframe src="HtmlWidget/dygraphs318.html" height="400" width="1000" style="border:none;"></iframe></center> <br><br> <div class="mySeryTitle">Connected scatterplot using base R</div> <hr> <p>Basic R also allows to build connected scatterplot thanks to the `line()` function. You just need to use the `b` option of the `type` argument. See examples below.</p> <div id="portfolio-items" class="row"> <div class="col-md-4 col-sm-6 portfolio-item"> <a class="portfolio-link" href="119-add-a-legend-to-a-plot.html"> <div class="portfolio-hover"> <div class="portfolio-hover-content"> <p>How to add a legend to base R plot</p> <hr> <p class="explanation_portfolio">The legend() function allows to add a legend. See how to use it with a list of available customization.</p> </div> </div> <img class="img-fluid imgOfPortfolio" src="img/graph/119-add-a-legend-to-a-plot.png" alt=""> </a> </div> <div class="col-md-4 col-sm-6 portfolio-item"> <a class="portfolio-link" href="120-plot-with-an-image-as-background.html"> <div class="portfolio-hover"> <div class="portfolio-hover-content"> <p>Image on the chart background</p> <hr> <p class="explanation_portfolio">The rasterImage function allows to add an image on the background of the chart.</p> </div> </div> <img class="img-fluid imgOfPortfolio" src="img/graph/120-plot-with-an-image-as-background.png" alt=""> </a> </div> <div class="col-md-4 col-sm-6 portfolio-item"> <a class="portfolio-link" href="191-manage-date-data.html"> <div class="portfolio-hover"> <div class="portfolio-hover-content"> <p>Manage date data</p> <hr> <p class="explanation_portfolio">Learn why it is important that your date is recognized at the date format, and how to do so.</p> </div> </div> <img class="img-fluid imgOfPortfolio" src="img/graph/191-manage-date-data.png" alt=""> </a> </div> <div class="col-md-4 col-sm-6 portfolio-item"> <a class="portfolio-link" href="6-graph-parameters-reminder.html"> <div class="portfolio-hover"> <div class="portfolio-hover-content"> <p>Parameters reminder</p> <hr> <p class="explanation_portfolio">A cheatsheet to quickly reminder what option to use with what value to customize your chart.</p> </div> </div> <img class="img-fluid imgOfPortfolio" src="img/graph/6-graph-parameters-reminder.png" alt=""> </a> </div> </div> </div> </section> <!-- ======================================================================= --> <!-- ============================ RELATED SECTION ============================ --> <section class="bg-light" id="portfolio_landing" style="padding-top: 30px; padding-bottom: 30px; margin-top: 100px;"> <div class="container"> <p class="mySeryTitle">Related chart types</p> <hr> <div class="row"> <div class="col-md-2 col-sm-4 portfolio-item "> <a class="portfolio-link" href="scatterplot.html"> <div class="portfolio-hover"> <div class="portfolio-hover-content"> <i class="fa fa-plus fa-3x"></i> </div> </div> <img class="img-fluid" src="img/section/ScatterPlot150.png" alt=""> </a> <div class="captionPortfolio">Scatter</div> </div> <div class="col-md-2 col-sm-4 portfolio-item"> <a class="portfolio-link" href="heatmap.html"> <div class="portfolio-hover"> <div class="portfolio-hover-content"> <i class="fa fa-plus fa-3x"></i> </div> </div> <img class="img-fluid" src="img/section/Heatmap150.png" alt=""> </a> <div class="captionPortfolio">Heatmap</div> </div> <div class="col-md-2 col-sm-4 portfolio-item"> <a class="portfolio-link" href="correlogram.html"> <div class="portfolio-hover"> <div class="portfolio-hover-content"> <i class="fa fa-plus fa-3x"></i> </div> </div> <img class="img-fluid" src="img/section/Correlogram150.png" alt=""> </a> <div class="captionPortfolio">Correlogram</div> </div> <div class="col-md-2 col-sm-4 portfolio-item"> <a class="portfolio-link" href="bubble-chart.html"> <div class="portfolio-hover"> <div class="portfolio-hover-content"> <i class="fa fa-plus fa-3x"></i> </div> </div> <img class="img-fluid" src="img/section/BubblePlot150.png" alt=""> </a> <div class="captionPortfolio">Bubble</div> </div> <div class="col-md-2 col-sm-4 portfolio-item "> <a class="portfolio-link" href="connected-scatterplot.html"> <div class="portfolio-hover"> <div class="portfolio-hover-content"> <i class="fa fa-plus fa-3x"></i> </div> </div> <img class="img-fluid" src="img/section/ScatterConnected150.png" alt=""> </a> <div class="captionPortfolio">Connected scatter</div> </div> <div class="col-md-2 col-sm-4 portfolio-item show column correlation numonly bigdata"> <a class="portfolio-link" href="2d-density-chart.html"> <div class="portfolio-hover"> <div class="portfolio-hover-content"> <i class="fa fa-plus fa-3x"></i> </div> </div> <img class="img-fluid" src="img/section/2dDensity150.png" alt=""> </a> <div class="captionPortfolio">Density 2d</div> </div> </div> </div> </section> <!-- ============================ CONTACT SECTION ============================ --> <!-- ANCHOR --> <a name="contactanchor"></a> <section id="contact" class="bg" style="background-color: white"></section> <!-- THIS ALLOWS TO INSERT THE CONTACT CHUNK THAT IS STORED IN A CONTACT.HTML FILE--> <script> $(function(){ $("#contact").load("html_chunk/contact.html"); }); </script> <!-- ============================ FOOTER SECTION ============================ --> <footer class="bg-light" id="myFooter"></footer> <!-- THIS ALLOWS TO INSERT THE FOOTER THAT IS STORED IN A FOOTER.HTML FILE--> <script> $(function(){ $("#myFooter").load("html_chunk/footer.html"); }); </script> <!-- ============================ --> <!-- =============== JAVASCRIPT SECTION =============== --> <!-- Bootstrap core JavaScript --> <script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script> <!-- Plugin JavaScript --> <script src="vendor/jquery-easing/jquery.easing.min.js"></script> <!-- Custom scripts for this template --> <script src="js/agency.min.js"></script> <!--============================== --> </body> </html>