<?xml version="1.0" encoding="UTF-8"?>
<rss  xmlns:atom="http://www.w3.org/2005/Atom" 
      xmlns:media="http://search.yahoo.com/mrss/" 
      xmlns:content="http://purl.org/rss/1.0/modules/content/" 
      xmlns:dc="http://purl.org/dc/elements/1.1/" 
      version="2.0">
<channel>
<title>CanvasXpress Recipes</title>
<link>https://neuhausi.github.io/canvasxpress-blog/r.html</link>
<atom:link href="https://neuhausi.github.io/canvasxpress-blog/r.xml" rel="self" type="application/rss+xml"/>
<description>Interactive, reproducible scientific visualization with canvasXpress — in R, Python and JavaScript.</description>
<generator>quarto-1.6.39</generator>
<lastBuildDate>Fri, 06 Nov 2026 05:00:00 GMT</lastBuildDate>
<item>
  <title>Interactive, reproducible figures inside teal</title>
  <dc:creator>Isaac Neuhaus</dc:creator>
  <link>https://neuhausi.github.io/canvasxpress-blog/posts/r/interactive-figures-in-teal/</link>
  <description><![CDATA[ 




<p>If you build Shiny apps with <a href="https://github.com/insightsengineering/teal">teal</a>, you know <code>plot_with_settings</code> — the module that wraps a plot with resize, full-screen, and download controls. Until now it rendered only <em>static</em> R graphics: ggplot, lattice, grob, base. Return anything else from <code>plot_r</code> and it quietly fell through and never drew.</p>
<p>That leaves a gap. The analyst looking at a volcano plot, a Kaplan–Meier curve, or a forest plot often wants to hover a point, select a group, and take the exact figure with them — not screenshot a PNG. In a submission-grade workflow they also want that figure to be <em>reproducible</em>: the chart and the code that made it, together.</p>
<section id="a-small-change-with-a-big-surface" class="level2">
<h2 class="anchored" data-anchor-id="a-small-change-with-a-big-surface">A small change with a big surface</h2>
<p><a href="https://github.com/pharmaverse/teal.widgets/pull/371">A PR on teal.widgets</a> adds a render path for interactive <strong>htmlwidgets</strong>. If <code>plot_r()</code> returns an htmlwidget — canvasXpress, plotly, anything with a Shiny binding — <code>plot_with_settings</code> renders it through the widget’s own binding, keeping the familiar card chrome. Height, width, and full-screen work as before, and <strong>download produces a self-contained HTML file</strong> you can email or archive.</p>
<p>It is strictly <strong>opt-in</strong>. Every existing static-plot caller behaves exactly as it did; the interactive path triggers only when a module author chooses to return a widget.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(shiny)</span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(canvasXpress)</span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(teal.widgets)</span>
<span id="cb1-4"></span>
<span id="cb1-5">pg <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.data.frame</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">na.omit</span>(palmerpenguins<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>penguins))</span>
<span id="cb1-6"></span>
<span id="cb1-7">ui <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> bslib<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">page_fluid</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot_with_settings_ui</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"p"</span>))</span>
<span id="cb1-8"></span>
<span id="cb1-9">server <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(input, output, session) {</span>
<span id="cb1-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot_with_settings_srv</span>(</span>
<span id="cb1-11">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"p"</span>,</span>
<span id="cb1-12">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot_r =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reactive</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">canvasXpress</span>(</span>
<span id="cb1-13">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> pg, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">graphType =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Scatter2D"</span>,</span>
<span id="cb1-14">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xAxis =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"flipper_length_mm"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yAxis =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"body_mass_g"</span>),</span>
<span id="cb1-15">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colorBy =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"species"</span></span>
<span id="cb1-16">    ))</span>
<span id="cb1-17">  )</span>
<span id="cb1-18">}</span>
<span id="cb1-19"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">shinyApp</span>(ui, server)</span></code></pre></div>
</div>
<p>The chart that lands in the card is a real canvasXpress widget — the same one you can render on its own here. Hover a point, click to select, use the toolbar to export:</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(canvasXpress)</span>
<span id="cb2-2"></span>
<span id="cb2-3">pg <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.data.frame</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">na.omit</span>(palmerpenguins<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>penguins))</span>
<span id="cb2-4"></span>
<span id="cb2-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">canvasXpress</span>(</span>
<span id="cb2-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data      =</span> pg,</span>
<span id="cb2-7">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">graphType =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Scatter2D"</span>,</span>
<span id="cb2-8">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xAxis     =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"flipper_length_mm"</span>),</span>
<span id="cb2-9">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yAxis     =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"body_mass_g"</span>),</span>
<span id="cb2-10">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colorBy   =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"species"</span>,</span>
<span id="cb2-11">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title     =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Palmer penguins — flipper length vs body mass"</span></span>
<span id="cb2-12">)</span></code></pre></div>
<div class="cell-output-display">
<div id="htmlwidget-1f02dc9b53bfcfc60a3f" style="width:100%;height:433px;" class="canvasXpress html-widget"></div>
<script type="application/json" data-for="htmlwidget-1f02dc9b53bfcfc60a3f">{"x":{"data":{"y":{"vars":["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45","46","47","48","49","50","51","52","53","54","55","56","57","58","59","60","61","62","63","64","65","66","67","68","69","70","71","72","73","74","75","76","77","78","79","80","81","82","83","84","85","86","87","88","89","90","91","92","93","94","95","96","97","98","99","100","101","102","103","104","105","106","107","108","109","110","111","112","113","114","115","116","117","118","119","120","121","122","123","124","125","126","127","128","129","130","131","132","133","134","135","136","137","138","139","140","141","142","143","144","145","146","147","148","149","150","151","152","153","154","155","156","157","158","159","160","161","162","163","164","165","166","167","168","169","170","171","172","173","174","175","176","177","178","179","180","181","182","183","184","185","186","187","188","189","190","191","192","193","194","195","196","197","198","199","200","201","202","203","204","205","206","207","208","209","210","211","212","213","214","215","216","217","218","219","220","221","222","223","224","225","226","227","228","229","230","231","232","233","234","235","236","237","238","239","240","241","242","243","244","245","246","247","248","249","250","251","252","253","254","255","256","257","258","259","260","261","262","263","264","265","266","267","268","269","270","271","272","273","274","275","276","277","278","279","280","281","282","283","284","285","286","287","288","289","290","291","292","293","294","295","296","297","298","299","300","301","302","303","304","305","306","307","308","309","310","311","312","313","314","315","316","317","318","319","320","321","322","323","324","325","326","327","328","329","330","331","332","333"],"smps":["species","island","bill_length_mm","bill_depth_mm","flipper_length_mm","body_mass_g","sex","year"],"data":[["Adelie","Torgersen","39.1","18.7","181","3750","male","2007"],["Adelie","Torgersen","39.5","17.4","186","3800","female","2007"],["Adelie","Torgersen","40.3","18.0","195","3250","female","2007"],["Adelie","Torgersen","36.7","19.3","193","3450","female","2007"],["Adelie","Torgersen","39.3","20.6","190","3650","male","2007"],["Adelie","Torgersen","38.9","17.8","181","3625","female","2007"],["Adelie","Torgersen","39.2","19.6","195","4675","male","2007"],["Adelie","Torgersen","41.1","17.6","182","3200","female","2007"],["Adelie","Torgersen","38.6","21.2","191","3800","male","2007"],["Adelie","Torgersen","34.6","21.1","198","4400","male","2007"],["Adelie","Torgersen","36.6","17.8","185","3700","female","2007"],["Adelie","Torgersen","38.7","19.0","195","3450","female","2007"],["Adelie","Torgersen","42.5","20.7","197","4500","male","2007"],["Adelie","Torgersen","34.4","18.4","184","3325","female","2007"],["Adelie","Torgersen","46.0","21.5","194","4200","male","2007"],["Adelie","Biscoe","37.8","18.3","174","3400","female","2007"],["Adelie","Biscoe","37.7","18.7","180","3600","male","2007"],["Adelie","Biscoe","35.9","19.2","189","3800","female","2007"],["Adelie","Biscoe","38.2","18.1","185","3950","male","2007"],["Adelie","Biscoe","38.8","17.2","180","3800","male","2007"],["Adelie","Biscoe","35.3","18.9","187","3800","female","2007"],["Adelie","Biscoe","40.6","18.6","183","3550","male","2007"],["Adelie","Biscoe","40.5","17.9","187","3200","female","2007"],["Adelie","Biscoe","37.9","18.6","172","3150","female","2007"],["Adelie","Biscoe","40.5","18.9","180","3950","male","2007"],["Adelie","Dream","39.5","16.7","178","3250","female","2007"],["Adelie","Dream","37.2","18.1","178","3900","male","2007"],["Adelie","Dream","39.5","17.8","188","3300","female","2007"],["Adelie","Dream","40.9","18.9","184","3900","male","2007"],["Adelie","Dream","36.4","17.0","195","3325","female","2007"],["Adelie","Dream","39.2","21.1","196","4150","male","2007"],["Adelie","Dream","38.8","20.0","190","3950","male","2007"],["Adelie","Dream","42.2","18.5","180","3550","female","2007"],["Adelie","Dream","37.6","19.3","181","3300","female","2007"],["Adelie","Dream","39.8","19.1","184","4650","male","2007"],["Adelie","Dream","36.5","18.0","182","3150","female","2007"],["Adelie","Dream","40.8","18.4","195","3900","male","2007"],["Adelie","Dream","36.0","18.5","186","3100","female","2007"],["Adelie","Dream","44.1","19.7","196","4400","male","2007"],["Adelie","Dream","37.0","16.9","185","3000","female","2007"],["Adelie","Dream","39.6","18.8","190","4600","male","2007"],["Adelie","Dream","41.1","19.0","182","3425","male","2007"],["Adelie","Dream","36.0","17.9","190","3450","female","2007"],["Adelie","Dream","42.3","21.2","191","4150","male","2007"],["Adelie","Biscoe","39.6","17.7","186","3500","female","2008"],["Adelie","Biscoe","40.1","18.9","188","4300","male","2008"],["Adelie","Biscoe","35.0","17.9","190","3450","female","2008"],["Adelie","Biscoe","42.0","19.5","200","4050","male","2008"],["Adelie","Biscoe","34.5","18.1","187","2900","female","2008"],["Adelie","Biscoe","41.4","18.6","191","3700","male","2008"],["Adelie","Biscoe","39.0","17.5","186","3550","female","2008"],["Adelie","Biscoe","40.6","18.8","193","3800","male","2008"],["Adelie","Biscoe","36.5","16.6","181","2850","female","2008"],["Adelie","Biscoe","37.6","19.1","194","3750","male","2008"],["Adelie","Biscoe","35.7","16.9","185","3150","female","2008"],["Adelie","Biscoe","41.3","21.1","195","4400","male","2008"],["Adelie","Biscoe","37.6","17.0","185","3600","female","2008"],["Adelie","Biscoe","41.1","18.2","192","4050","male","2008"],["Adelie","Biscoe","36.4","17.1","184","2850","female","2008"],["Adelie","Biscoe","41.6","18.0","192","3950","male","2008"],["Adelie","Biscoe","35.5","16.2","195","3350","female","2008"],["Adelie","Biscoe","41.1","19.1","188","4100","male","2008"],["Adelie","Torgersen","35.9","16.6","190","3050","female","2008"],["Adelie","Torgersen","41.8","19.4","198","4450","male","2008"],["Adelie","Torgersen","33.5","19.0","190","3600","female","2008"],["Adelie","Torgersen","39.7","18.4","190","3900","male","2008"],["Adelie","Torgersen","39.6","17.2","196","3550","female","2008"],["Adelie","Torgersen","45.8","18.9","197","4150","male","2008"],["Adelie","Torgersen","35.5","17.5","190","3700","female","2008"],["Adelie","Torgersen","42.8","18.5","195","4250","male","2008"],["Adelie","Torgersen","40.9","16.8","191","3700","female","2008"],["Adelie","Torgersen","37.2","19.4","184","3900","male","2008"],["Adelie","Torgersen","36.2","16.1","187","3550","female","2008"],["Adelie","Torgersen","42.1","19.1","195","4000","male","2008"],["Adelie","Torgersen","34.6","17.2","189","3200","female","2008"],["Adelie","Torgersen","42.9","17.6","196","4700","male","2008"],["Adelie","Torgersen","36.7","18.8","187","3800","female","2008"],["Adelie","Torgersen","35.1","19.4","193","4200","male","2008"],["Adelie","Dream","37.3","17.8","191","3350","female","2008"],["Adelie","Dream","41.3","20.3","194","3550","male","2008"],["Adelie","Dream","36.3","19.5","190","3800","male","2008"],["Adelie","Dream","36.9","18.6","189","3500","female","2008"],["Adelie","Dream","38.3","19.2","189","3950","male","2008"],["Adelie","Dream","38.9","18.8","190","3600","female","2008"],["Adelie","Dream","35.7","18.0","202","3550","female","2008"],["Adelie","Dream","41.1","18.1","205","4300","male","2008"],["Adelie","Dream","34.0","17.1","185","3400","female","2008"],["Adelie","Dream","39.6","18.1","186","4450","male","2008"],["Adelie","Dream","36.2","17.3","187","3300","female","2008"],["Adelie","Dream","40.8","18.9","208","4300","male","2008"],["Adelie","Dream","38.1","18.6","190","3700","female","2008"],["Adelie","Dream","40.3","18.5","196","4350","male","2008"],["Adelie","Dream","33.1","16.1","178","2900","female","2008"],["Adelie","Dream","43.2","18.5","192","4100","male","2008"],["Adelie","Biscoe","35.0","17.9","192","3725","female","2009"],["Adelie","Biscoe","41.0","20.0","203","4725","male","2009"],["Adelie","Biscoe","37.7","16.0","183","3075","female","2009"],["Adelie","Biscoe","37.8","20.0","190","4250","male","2009"],["Adelie","Biscoe","37.9","18.6","193","2925","female","2009"],["Adelie","Biscoe","39.7","18.9","184","3550","male","2009"],["Adelie","Biscoe","38.6","17.2","199","3750","female","2009"],["Adelie","Biscoe","38.2","20.0","190","3900","male","2009"],["Adelie","Biscoe","38.1","17.0","181","3175","female","2009"],["Adelie","Biscoe","43.2","19.0","197","4775","male","2009"],["Adelie","Biscoe","38.1","16.5","198","3825","female","2009"],["Adelie","Biscoe","45.6","20.3","191","4600","male","2009"],["Adelie","Biscoe","39.7","17.7","193","3200","female","2009"],["Adelie","Biscoe","42.2","19.5","197","4275","male","2009"],["Adelie","Biscoe","39.6","20.7","191","3900","female","2009"],["Adelie","Biscoe","42.7","18.3","196","4075","male","2009"],["Adelie","Torgersen","38.6","17.0","188","2900","female","2009"],["Adelie","Torgersen","37.3","20.5","199","3775","male","2009"],["Adelie","Torgersen","35.7","17.0","189","3350","female","2009"],["Adelie","Torgersen","41.1","18.6","189","3325","male","2009"],["Adelie","Torgersen","36.2","17.2","187","3150","female","2009"],["Adelie","Torgersen","37.7","19.8","198","3500","male","2009"],["Adelie","Torgersen","40.2","17.0","176","3450","female","2009"],["Adelie","Torgersen","41.4","18.5","202","3875","male","2009"],["Adelie","Torgersen","35.2","15.9","186","3050","female","2009"],["Adelie","Torgersen","40.6","19.0","199","4000","male","2009"],["Adelie","Torgersen","38.8","17.6","191","3275","female","2009"],["Adelie","Torgersen","41.5","18.3","195","4300","male","2009"],["Adelie","Torgersen","39.0","17.1","191","3050","female","2009"],["Adelie","Torgersen","44.1","18.0","210","4000","male","2009"],["Adelie","Torgersen","38.5","17.9","190","3325","female","2009"],["Adelie","Torgersen","43.1","19.2","197","3500","male","2009"],["Adelie","Dream","36.8","18.5","193","3500","female","2009"],["Adelie","Dream","37.5","18.5","199","4475","male","2009"],["Adelie","Dream","38.1","17.6","187","3425","female","2009"],["Adelie","Dream","41.1","17.5","190","3900","male","2009"],["Adelie","Dream","35.6","17.5","191","3175","female","2009"],["Adelie","Dream","40.2","20.1","200","3975","male","2009"],["Adelie","Dream","37.0","16.5","185","3400","female","2009"],["Adelie","Dream","39.7","17.9","193","4250","male","2009"],["Adelie","Dream","40.2","17.1","193","3400","female","2009"],["Adelie","Dream","40.6","17.2","187","3475","male","2009"],["Adelie","Dream","32.1","15.5","188","3050","female","2009"],["Adelie","Dream","40.7","17.0","190","3725","male","2009"],["Adelie","Dream","37.3","16.8","192","3000","female","2009"],["Adelie","Dream","39.0","18.7","185","3650","male","2009"],["Adelie","Dream","39.2","18.6","190","4250","male","2009"],["Adelie","Dream","36.6","18.4","184","3475","female","2009"],["Adelie","Dream","36.0","17.8","195","3450","female","2009"],["Adelie","Dream","37.8","18.1","193","3750","male","2009"],["Adelie","Dream","36.0","17.1","187","3700","female","2009"],["Adelie","Dream","41.5","18.5","201","4000","male","2009"],["Gentoo","Biscoe","46.1","13.2","211","4500","female","2007"],["Gentoo","Biscoe","50.0","16.3","230","5700","male","2007"],["Gentoo","Biscoe","48.7","14.1","210","4450","female","2007"],["Gentoo","Biscoe","50.0","15.2","218","5700","male","2007"],["Gentoo","Biscoe","47.6","14.5","215","5400","male","2007"],["Gentoo","Biscoe","46.5","13.5","210","4550","female","2007"],["Gentoo","Biscoe","45.4","14.6","211","4800","female","2007"],["Gentoo","Biscoe","46.7","15.3","219","5200","male","2007"],["Gentoo","Biscoe","43.3","13.4","209","4400","female","2007"],["Gentoo","Biscoe","46.8","15.4","215","5150","male","2007"],["Gentoo","Biscoe","40.9","13.7","214","4650","female","2007"],["Gentoo","Biscoe","49.0","16.1","216","5550","male","2007"],["Gentoo","Biscoe","45.5","13.7","214","4650","female","2007"],["Gentoo","Biscoe","48.4","14.6","213","5850","male","2007"],["Gentoo","Biscoe","45.8","14.6","210","4200","female","2007"],["Gentoo","Biscoe","49.3","15.7","217","5850","male","2007"],["Gentoo","Biscoe","42.0","13.5","210","4150","female","2007"],["Gentoo","Biscoe","49.2","15.2","221","6300","male","2007"],["Gentoo","Biscoe","46.2","14.5","209","4800","female","2007"],["Gentoo","Biscoe","48.7","15.1","222","5350","male","2007"],["Gentoo","Biscoe","50.2","14.3","218","5700","male","2007"],["Gentoo","Biscoe","45.1","14.5","215","5000","female","2007"],["Gentoo","Biscoe","46.5","14.5","213","4400","female","2007"],["Gentoo","Biscoe","46.3","15.8","215","5050","male","2007"],["Gentoo","Biscoe","42.9","13.1","215","5000","female","2007"],["Gentoo","Biscoe","46.1","15.1","215","5100","male","2007"],["Gentoo","Biscoe","47.8","15.0","215","5650","male","2007"],["Gentoo","Biscoe","48.2","14.3","210","4600","female","2007"],["Gentoo","Biscoe","50.0","15.3","220","5550","male","2007"],["Gentoo","Biscoe","47.3","15.3","222","5250","male","2007"],["Gentoo","Biscoe","42.8","14.2","209","4700","female","2007"],["Gentoo","Biscoe","45.1","14.5","207","5050","female","2007"],["Gentoo","Biscoe","59.6","17.0","230","6050","male","2007"],["Gentoo","Biscoe","49.1","14.8","220","5150","female","2008"],["Gentoo","Biscoe","48.4","16.3","220","5400","male","2008"],["Gentoo","Biscoe","42.6","13.7","213","4950","female","2008"],["Gentoo","Biscoe","44.4","17.3","219","5250","male","2008"],["Gentoo","Biscoe","44.0","13.6","208","4350","female","2008"],["Gentoo","Biscoe","48.7","15.7","208","5350","male","2008"],["Gentoo","Biscoe","42.7","13.7","208","3950","female","2008"],["Gentoo","Biscoe","49.6","16.0","225","5700","male","2008"],["Gentoo","Biscoe","45.3","13.7","210","4300","female","2008"],["Gentoo","Biscoe","49.6","15.0","216","4750","male","2008"],["Gentoo","Biscoe","50.5","15.9","222","5550","male","2008"],["Gentoo","Biscoe","43.6","13.9","217","4900","female","2008"],["Gentoo","Biscoe","45.5","13.9","210","4200","female","2008"],["Gentoo","Biscoe","50.5","15.9","225","5400","male","2008"],["Gentoo","Biscoe","44.9","13.3","213","5100","female","2008"],["Gentoo","Biscoe","45.2","15.8","215","5300","male","2008"],["Gentoo","Biscoe","46.6","14.2","210","4850","female","2008"],["Gentoo","Biscoe","48.5","14.1","220","5300","male","2008"],["Gentoo","Biscoe","45.1","14.4","210","4400","female","2008"],["Gentoo","Biscoe","50.1","15.0","225","5000","male","2008"],["Gentoo","Biscoe","46.5","14.4","217","4900","female","2008"],["Gentoo","Biscoe","45.0","15.4","220","5050","male","2008"],["Gentoo","Biscoe","43.8","13.9","208","4300","female","2008"],["Gentoo","Biscoe","45.5","15.0","220","5000","male","2008"],["Gentoo","Biscoe","43.2","14.5","208","4450","female","2008"],["Gentoo","Biscoe","50.4","15.3","224","5550","male","2008"],["Gentoo","Biscoe","45.3","13.8","208","4200","female","2008"],["Gentoo","Biscoe","46.2","14.9","221","5300","male","2008"],["Gentoo","Biscoe","45.7","13.9","214","4400","female","2008"],["Gentoo","Biscoe","54.3","15.7","231","5650","male","2008"],["Gentoo","Biscoe","45.8","14.2","219","4700","female","2008"],["Gentoo","Biscoe","49.8","16.8","230","5700","male","2008"],["Gentoo","Biscoe","49.5","16.2","229","5800","male","2008"],["Gentoo","Biscoe","43.5","14.2","220","4700","female","2008"],["Gentoo","Biscoe","50.7","15.0","223","5550","male","2008"],["Gentoo","Biscoe","47.7","15.0","216","4750","female","2008"],["Gentoo","Biscoe","46.4","15.6","221","5000","male","2008"],["Gentoo","Biscoe","48.2","15.6","221","5100","male","2008"],["Gentoo","Biscoe","46.5","14.8","217","5200","female","2008"],["Gentoo","Biscoe","46.4","15.0","216","4700","female","2008"],["Gentoo","Biscoe","48.6","16.0","230","5800","male","2008"],["Gentoo","Biscoe","47.5","14.2","209","4600","female","2008"],["Gentoo","Biscoe","51.1","16.3","220","6000","male","2008"],["Gentoo","Biscoe","45.2","13.8","215","4750","female","2008"],["Gentoo","Biscoe","45.2","16.4","223","5950","male","2008"],["Gentoo","Biscoe","49.1","14.5","212","4625","female","2009"],["Gentoo","Biscoe","52.5","15.6","221","5450","male","2009"],["Gentoo","Biscoe","47.4","14.6","212","4725","female","2009"],["Gentoo","Biscoe","50.0","15.9","224","5350","male","2009"],["Gentoo","Biscoe","44.9","13.8","212","4750","female","2009"],["Gentoo","Biscoe","50.8","17.3","228","5600","male","2009"],["Gentoo","Biscoe","43.4","14.4","218","4600","female","2009"],["Gentoo","Biscoe","51.3","14.2","218","5300","male","2009"],["Gentoo","Biscoe","47.5","14.0","212","4875","female","2009"],["Gentoo","Biscoe","52.1","17.0","230","5550","male","2009"],["Gentoo","Biscoe","47.5","15.0","218","4950","female","2009"],["Gentoo","Biscoe","52.2","17.1","228","5400","male","2009"],["Gentoo","Biscoe","45.5","14.5","212","4750","female","2009"],["Gentoo","Biscoe","49.5","16.1","224","5650","male","2009"],["Gentoo","Biscoe","44.5","14.7","214","4850","female","2009"],["Gentoo","Biscoe","50.8","15.7","226","5200","male","2009"],["Gentoo","Biscoe","49.4","15.8","216","4925","male","2009"],["Gentoo","Biscoe","46.9","14.6","222","4875","female","2009"],["Gentoo","Biscoe","48.4","14.4","203","4625","female","2009"],["Gentoo","Biscoe","51.1","16.5","225","5250","male","2009"],["Gentoo","Biscoe","48.5","15.0","219","4850","female","2009"],["Gentoo","Biscoe","55.9","17.0","228","5600","male","2009"],["Gentoo","Biscoe","47.2","15.5","215","4975","female","2009"],["Gentoo","Biscoe","49.1","15.0","228","5500","male","2009"],["Gentoo","Biscoe","46.8","16.1","215","5500","male","2009"],["Gentoo","Biscoe","41.7","14.7","210","4700","female","2009"],["Gentoo","Biscoe","53.4","15.8","219","5500","male","2009"],["Gentoo","Biscoe","43.3","14.0","208","4575","female","2009"],["Gentoo","Biscoe","48.1","15.1","209","5500","male","2009"],["Gentoo","Biscoe","50.5","15.2","216","5000","female","2009"],["Gentoo","Biscoe","49.8","15.9","229","5950","male","2009"],["Gentoo","Biscoe","43.5","15.2","213","4650","female","2009"],["Gentoo","Biscoe","51.5","16.3","230","5500","male","2009"],["Gentoo","Biscoe","46.2","14.1","217","4375","female","2009"],["Gentoo","Biscoe","55.1","16.0","230","5850","male","2009"],["Gentoo","Biscoe","48.8","16.2","222","6000","male","2009"],["Gentoo","Biscoe","47.2","13.7","214","4925","female","2009"],["Gentoo","Biscoe","46.8","14.3","215","4850","female","2009"],["Gentoo","Biscoe","50.4","15.7","222","5750","male","2009"],["Gentoo","Biscoe","45.2","14.8","212","5200","female","2009"],["Gentoo","Biscoe","49.9","16.1","213","5400","male","2009"],["Chinstrap","Dream","46.5","17.9","192","3500","female","2007"],["Chinstrap","Dream","50.0","19.5","196","3900","male","2007"],["Chinstrap","Dream","51.3","19.2","193","3650","male","2007"],["Chinstrap","Dream","45.4","18.7","188","3525","female","2007"],["Chinstrap","Dream","52.7","19.8","197","3725","male","2007"],["Chinstrap","Dream","45.2","17.8","198","3950","female","2007"],["Chinstrap","Dream","46.1","18.2","178","3250","female","2007"],["Chinstrap","Dream","51.3","18.2","197","3750","male","2007"],["Chinstrap","Dream","46.0","18.9","195","4150","female","2007"],["Chinstrap","Dream","51.3","19.9","198","3700","male","2007"],["Chinstrap","Dream","46.6","17.8","193","3800","female","2007"],["Chinstrap","Dream","51.7","20.3","194","3775","male","2007"],["Chinstrap","Dream","47.0","17.3","185","3700","female","2007"],["Chinstrap","Dream","52.0","18.1","201","4050","male","2007"],["Chinstrap","Dream","45.9","17.1","190","3575","female","2007"],["Chinstrap","Dream","50.5","19.6","201","4050","male","2007"],["Chinstrap","Dream","50.3","20.0","197","3300","male","2007"],["Chinstrap","Dream","58.0","17.8","181","3700","female","2007"],["Chinstrap","Dream","46.4","18.6","190","3450","female","2007"],["Chinstrap","Dream","49.2","18.2","195","4400","male","2007"],["Chinstrap","Dream","42.4","17.3","181","3600","female","2007"],["Chinstrap","Dream","48.5","17.5","191","3400","male","2007"],["Chinstrap","Dream","43.2","16.6","187","2900","female","2007"],["Chinstrap","Dream","50.6","19.4","193","3800","male","2007"],["Chinstrap","Dream","46.7","17.9","195","3300","female","2007"],["Chinstrap","Dream","52.0","19.0","197","4150","male","2007"],["Chinstrap","Dream","50.5","18.4","200","3400","female","2008"],["Chinstrap","Dream","49.5","19.0","200","3800","male","2008"],["Chinstrap","Dream","46.4","17.8","191","3700","female","2008"],["Chinstrap","Dream","52.8","20.0","205","4550","male","2008"],["Chinstrap","Dream","40.9","16.6","187","3200","female","2008"],["Chinstrap","Dream","54.2","20.8","201","4300","male","2008"],["Chinstrap","Dream","42.5","16.7","187","3350","female","2008"],["Chinstrap","Dream","51.0","18.8","203","4100","male","2008"],["Chinstrap","Dream","49.7","18.6","195","3600","male","2008"],["Chinstrap","Dream","47.5","16.8","199","3900","female","2008"],["Chinstrap","Dream","47.6","18.3","195","3850","female","2008"],["Chinstrap","Dream","52.0","20.7","210","4800","male","2008"],["Chinstrap","Dream","46.9","16.6","192","2700","female","2008"],["Chinstrap","Dream","53.5","19.9","205","4500","male","2008"],["Chinstrap","Dream","49.0","19.5","210","3950","male","2008"],["Chinstrap","Dream","46.2","17.5","187","3650","female","2008"],["Chinstrap","Dream","50.9","19.1","196","3550","male","2008"],["Chinstrap","Dream","45.5","17.0","196","3500","female","2008"],["Chinstrap","Dream","50.9","17.9","196","3675","female","2009"],["Chinstrap","Dream","50.8","18.5","201","4450","male","2009"],["Chinstrap","Dream","50.1","17.9","190","3400","female","2009"],["Chinstrap","Dream","49.0","19.6","212","4300","male","2009"],["Chinstrap","Dream","51.5","18.7","187","3250","male","2009"],["Chinstrap","Dream","49.8","17.3","198","3675","female","2009"],["Chinstrap","Dream","48.1","16.4","199","3325","female","2009"],["Chinstrap","Dream","51.4","19.0","201","3950","male","2009"],["Chinstrap","Dream","45.7","17.3","193","3600","female","2009"],["Chinstrap","Dream","50.7","19.7","203","4050","male","2009"],["Chinstrap","Dream","42.5","17.3","187","3350","female","2009"],["Chinstrap","Dream","52.2","18.8","197","3450","male","2009"],["Chinstrap","Dream","45.2","16.6","191","3250","female","2009"],["Chinstrap","Dream","49.3","19.9","203","4050","male","2009"],["Chinstrap","Dream","50.2","18.8","202","3800","male","2009"],["Chinstrap","Dream","45.6","19.4","194","3525","female","2009"],["Chinstrap","Dream","51.9","19.5","206","3950","male","2009"],["Chinstrap","Dream","46.8","16.5","189","3650","female","2009"],["Chinstrap","Dream","45.7","17.0","195","3650","female","2009"],["Chinstrap","Dream","55.8","19.8","207","4000","male","2009"],["Chinstrap","Dream","43.5","18.1","202","3400","female","2009"],["Chinstrap","Dream","49.6","18.2","193","3775","male","2009"],["Chinstrap","Dream","50.8","19.0","210","4100","male","2009"],["Chinstrap","Dream","50.2","18.7","198","3775","female","2009"]]},"x":null,"z":null},"config":{"graphType":"Scatter2D","isR":true,"xAxis":["flipper_length_mm"],"yAxis":["body_mass_g"],"colorBy":"species","title":"Palmer penguins — flipper length vs body mass"},"events":null,"afterRender":null},"evals":[],"jsHooks":[]}</script>
</div>
</div>
<p>Inside <code>plot_with_settings</code>, that interactivity sits in the usual card, with the resize and download controls you already use:</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://neuhausi.github.io/canvasxpress-blog/posts/r/interactive-figures-in-teal/penguins-demo.gif" class="img-fluid figure-img"></p>
<figcaption>Three canvasXpress plots inside plot_with_settings — select an element, open the customizer, download as HTML.</figcaption>
</figure>
</div>
</section>
<section id="describe-the-chart-instead-of-configuring-it" class="level2">
<h2 class="anchored" data-anchor-id="describe-the-chart-instead-of-configuring-it">Describe the chart instead of configuring it</h2>
<p>Because the render path is generic, you inherit whatever the widget can do. canvasXpress, for instance, can build a chart from a plain-English prompt — no <code>graphType</code>, no axes:</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot_with_settings_srv</span>(</span>
<span id="cb3-2">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"p"</span>,</span>
<span id="cb3-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot_r =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reactive</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">canvasXpress</span>(</span>
<span id="cb3-4">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data   =</span> pg,</span>
<span id="cb3-5">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">prompt =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Create a scatter plot of bill_depth_mm vs body_mass_g and color by species"</span></span>
<span id="cb3-6">  ))</span>
<span id="cb3-7">)</span></code></pre></div>
</div>
</section>
<section id="try-it-live" class="level2">
<h2 class="anchored" data-anchor-id="try-it-live">Try it live</h2>
<p>There’s a running demo — three canvasXpress plots inside <code>plot_with_settings</code> cards:</p>
<p><a href="https://canvasxpress.shinyapps.io/teal-canvasxpress-demo/"><strong>canvasxpress.shinyapps.io/teal-canvasxpress-demo</strong></a></p>
<p>or install the PR build and run it yourself:</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1">pak<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pak</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pharmaverse/teal.widgets#371"</span>)</span></code></pre></div>
</div>
</section>
<section id="why-it-matters" class="level2">
<h2 class="anchored" data-anchor-id="why-it-matters">Why it matters</h2>
<p>Interactive dashboards usually mean leaving the tools you trust for a BI platform, and losing reproducibility in the trade. This keeps both: the module model and reproducible, code-defined figures of teal, plus the interactivity and portability of an htmlwidget. The figure is still code — it just moves now.</p>
<p>The discussion that started it is <a href="https://github.com/pharmaverse/teal/discussions/1757">teal#1757</a>; the PR is <a href="https://github.com/pharmaverse/teal.widgets/pull/371">teal.widgets#371</a>. Feedback from teal users is welcome, especially on how you’d want widget support wired into the module API.</p>


</section>

 ]]></description>
  <category>R</category>
  <category>canvasXpress</category>
  <category>shiny</category>
  <category>teal</category>
  <category>pharmaverse</category>
  <category>visualization</category>
  <guid>https://neuhausi.github.io/canvasxpress-blog/posts/r/interactive-figures-in-teal/</guid>
  <pubDate>Fri, 06 Nov 2026 05:00:00 GMT</pubDate>
  <media:content url="https://neuhausi.github.io/canvasxpress-blog/posts/r/interactive-figures-in-teal/thumbnail.png" medium="image" type="image/png" height="133" width="144"/>
</item>
<item>
  <title>Interactive network graphs in R with canvasXpress</title>
  <dc:creator>Isaac Neuhaus</dc:creator>
  <link>https://neuhausi.github.io/canvasxpress-blog/posts/r/network-graphs-in-r/</link>
  <description><![CDATA[ 




<p>A network graph shows <strong>relationships</strong>: nodes connected by edges, laid out so that connected things sit near each other. The usual R reach is <code>igraph</code> or <code>networkD3</code>, but here we build one with <a href="https://canvasxpress.org">canvasXpress</a> — draggable, hover-labelled, force-directed, and <strong>reproducible</strong>, because the whole figure is one portable <code>data</code> + <code>config</code> spec.</p>
<section id="the-data-shape" class="level2">
<h2 class="anchored" data-anchor-id="the-data-shape">The data shape</h2>
<p>canvasXpress builds a network from two tables: <strong>nodes</strong> (<code>id</code>, <code>name</code>, <code>group</code>) and <strong>edges</strong> (<code>id1</code>, <code>id2</code>, <code>value</code>). Swap this simulated three-community graph for your own.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(canvasXpress)</span>
<span id="cb1-2"></span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set.seed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb1-4">grp   <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Alpha"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Beta"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Gamma"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">each =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">7</span>)</span>
<span id="cb1-5">ids   <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"n"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq_along</span>(grp))</span>
<span id="cb1-6">nodes <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">id =</span> ids, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">name =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(grp, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ave</span>(grp, grp, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">FUN =</span> seq_along)),</span>
<span id="cb1-7">                    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group =</span> grp, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stringsAsFactors =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span>
<span id="cb1-8"></span>
<span id="cb1-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Dense within a community, sparse between communities — the structure a layout reveals.</span></span>
<span id="cb1-10">e1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(); e2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(); ev <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>()</span>
<span id="cb1-11"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (g <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>(grp)) {</span>
<span id="cb1-12">  m <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> ids[grp <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> g]</span>
<span id="cb1-13">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (i <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq_along</span>(m)) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (j <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq_along</span>(m))</span>
<span id="cb1-14">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (i <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> j <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">runif</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>) { e1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(e1, m[i]); e2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(e2, m[j]); ev <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(ev, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)) }</span>
<span id="cb1-15">}</span>
<span id="cb1-16"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (k <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>) {                                     <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># a few cross-community links</span></span>
<span id="cb1-17">  pair <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>(grp), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb1-18">  e1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(e1, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>(ids[grp <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> pair[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]], <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)); e2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(e2, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>(ids[grp <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> pair[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]], <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)); ev <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(ev, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb1-19">}</span>
<span id="cb1-20">edges <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">id1 =</span> e1, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">id2 =</span> e2, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value =</span> ev, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stringsAsFactors =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span></code></pre></div>
</div>
</section>
<section id="the-plot" class="level2">
<h2 class="anchored" data-anchor-id="the-plot">The plot</h2>
<p>Pass the two tables as <code>nodeData</code> and <code>edgeData</code>; <code>colorNodeBy</code> colours by the community, and <code>networkLayoutType = "forceDirected"</code> runs the physics simulation.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">canvasXpress</span>(</span>
<span id="cb2-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nodeData          =</span> nodes,</span>
<span id="cb2-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">edgeData          =</span> edges,</span>
<span id="cb2-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">graphType         =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Network"</span>,</span>
<span id="cb2-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">networkLayoutType =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"forceDirected"</span>,</span>
<span id="cb2-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colorNodeBy       =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"group"</span>,</span>
<span id="cb2-7">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nodeSize          =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span>,</span>
<span id="cb2-8">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">showAnimation     =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,</span>
<span id="cb2-9">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title             =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A small community network"</span>,</span>
<span id="cb2-10">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width             =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">650</span>,</span>
<span id="cb2-11">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">height            =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500</span></span>
<span id="cb2-12">)</span></code></pre></div>
<div class="cell-output-display">
<div id="htmlwidget-17b4dbd527e05259a22a" style="width:100%;height:500px;" class="canvasXpress html-widget"></div>
<script type="application/json" data-for="htmlwidget-17b4dbd527e05259a22a">{"x":{"data":{"nodes":[{"id":"n1","name":"Alpha1","group":"Alpha"},{"id":"n2","name":"Alpha2","group":"Alpha"},{"id":"n3","name":"Alpha3","group":"Alpha"},{"id":"n4","name":"Alpha4","group":"Alpha"},{"id":"n5","name":"Alpha5","group":"Alpha"},{"id":"n6","name":"Alpha6","group":"Alpha"},{"id":"n7","name":"Alpha7","group":"Alpha"},{"id":"n8","name":"Beta1","group":"Beta"},{"id":"n9","name":"Beta2","group":"Beta"},{"id":"n10","name":"Beta3","group":"Beta"},{"id":"n11","name":"Beta4","group":"Beta"},{"id":"n12","name":"Beta5","group":"Beta"},{"id":"n13","name":"Beta6","group":"Beta"},{"id":"n14","name":"Beta7","group":"Beta"},{"id":"n15","name":"Gamma1","group":"Gamma"},{"id":"n16","name":"Gamma2","group":"Gamma"},{"id":"n17","name":"Gamma3","group":"Gamma"},{"id":"n18","name":"Gamma4","group":"Gamma"},{"id":"n19","name":"Gamma5","group":"Gamma"},{"id":"n20","name":"Gamma6","group":"Gamma"},{"id":"n21","name":"Gamma7","group":"Gamma"}],"edges":[{"id1":"n1","id2":"n2","value":4},{"id1":"n1","id2":"n5","value":5},{"id1":"n2","id2":"n4","value":3},{"id1":"n2","id2":"n5","value":1},{"id1":"n2","id2":"n6","value":5},{"id1":"n2","id2":"n7","value":2},{"id1":"n3","id2":"n6","value":5},{"id1":"n3","id2":"n7","value":1},{"id1":"n4","id2":"n5","value":5},{"id1":"n4","id2":"n7","value":2},{"id1":"n5","id2":"n7","value":4},{"id1":"n8","id2":"n11","value":2},{"id1":"n9","id2":"n13","value":4},{"id1":"n10","id2":"n12","value":1},{"id1":"n10","id2":"n13","value":4},{"id1":"n10","id2":"n14","value":2},{"id1":"n11","id2":"n12","value":3},{"id1":"n11","id2":"n13","value":2},{"id1":"n12","id2":"n13","value":1},{"id1":"n12","id2":"n14","value":3},{"id1":"n15","id2":"n17","value":4},{"id1":"n15","id2":"n18","value":3},{"id1":"n15","id2":"n20","value":5},{"id1":"n15","id2":"n21","value":1},{"id1":"n16","id2":"n17","value":1},{"id1":"n16","id2":"n18","value":4},{"id1":"n16","id2":"n21","value":4},{"id1":"n17","id2":"n21","value":1},{"id1":"n18","id2":"n20","value":1},{"id1":"n20","id2":"n21","value":2},{"id1":"n10","id2":"n20","value":1},{"id1":"n14","id2":"n21","value":1},{"id1":"n16","id2":"n2","value":1},{"id1":"n3","id2":"n16","value":1},{"id1":"n19","id2":"n9","value":1},{"id1":"n7","id2":"n14","value":1}],"groups":null,"constraints":null},"config":{"graphType":"Network","isR":true,"networkLayoutType":"forceDirected","colorNodeBy":"group","nodeSize":25,"showAnimation":true,"title":"A small community network"},"events":null,"afterRender":null},"evals":[],"jsHooks":[]}</script>
</div>
</div>
<p>Drag any node and the layout settles around it; hover to read the label. The three communities separate on their own because within-group edges outnumber the cross-group ones.</p>
</section>
<section id="why-reproducible" class="level2">
<h2 class="anchored" data-anchor-id="why-reproducible">Why “reproducible”</h2>
<p>The nodes, edges and <code>config</code> <strong>are</strong> the figure — one portable specification. The same spec renders the identical network from Python or JavaScript, and can be validated and re-rendered later.</p>
</section>
<section id="next" class="level2">
<h2 class="anchored" data-anchor-id="next">Next</h2>
<ul>
<li><a href="../sankey-diagrams-in-r/">Sankey / alluvial diagrams in R</a></li>
<li>Gallery: <a href="https://canvasxpress.org/examples.html" class="uri">https://canvasxpress.org/examples.html</a></li>
<li>Package: <a href="https://github.com/neuhausi/canvasXpress" class="uri">https://github.com/neuhausi/canvasXpress</a></li>
</ul>


</section>

 ]]></description>
  <category>R</category>
  <category>canvasXpress</category>
  <category>network</category>
  <category>visualization</category>
  <guid>https://neuhausi.github.io/canvasxpress-blog/posts/r/network-graphs-in-r/</guid>
  <pubDate>Thu, 29 Oct 2026 04:00:00 GMT</pubDate>
  <media:content url="https://neuhausi.github.io/canvasxpress-blog/posts/r/network-graphs-in-r/thumbnail.png" medium="image" type="image/png" height="144" width="144"/>
</item>
<item>
  <title>An interactive NGS sequencing-QC dashboard in R with canvasXpress</title>
  <dc:creator>Isaac Neuhaus</dc:creator>
  <link>https://neuhausi.github.io/canvasxpress-blog/posts/r/linked-dashboards-in-r/</link>
  <description><![CDATA[ 




<p>After a sequencing run you get a QC table — one row per sample, a dozen metrics — and you need to answer three questions fast: <strong>which samples fail, is a whole batch off, and are the failures correlated?</strong> A single scatter can’t do it; you want several views that <strong>talk to each other</strong> — select a suspicious sample in one and see it light up in the rest. In R that usually means Shiny (a server, reactive wiring). canvasXpress does it client-side: give every panel the same <strong>broadcast group</strong> and a selection broadcasts to all of them. Here we build a real QC dashboard for 96 RNA/exome samples.</p>
<section id="the-qc-table" class="level2">
<h2 class="anchored" data-anchor-id="the-qc-table">The QC table</h2>
<p>96 samples with mapping rate, duplication, Q30, GC, insert size and contamination (VerifyBamID <code>freemix</code>), plus lane / batch / library annotations. (Download: <a href="ngs-qc.csv"><code>ngs-qc.csv</code></a>.)</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(canvasXpress)</span>
<span id="cb1-2"></span>
<span id="cb1-3">qc <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read.csv</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ngs-qc.csv"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stringsAsFactors =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span>
<span id="cb1-4">metrics <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"total_reads"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pct_mapped"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pct_duplication"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pct_q30"</span>,</span>
<span id="cb1-5">             <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"gc_content"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"insert_size"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"contamination_freemix"</span>)</span>
<span id="cb1-6"></span>
<span id="cb1-7">m        <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.matrix</span>(qc[, metrics]); <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rownames</span>(m) <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> qc<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>sample</span>
<span id="cb1-8">annot    <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Lane =</span> qc<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>lane, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Batch =</span> qc<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>batch, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Library =</span> qc<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>library,</span>
<span id="cb1-9">                      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">row.names =</span> qc<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>sample)</span>
<span id="cb1-10"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(qc[, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sample"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"batch"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"library"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pct_mapped"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pct_duplication"</span>,</span>
<span id="cb1-11">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"contamination_freemix"</span>)], <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>)</span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>  sample batch  library pct_mapped pct_duplication contamination_freemix
1   S001  RunA    PolyA      93.85           11.90                0.0165
2   S002  RunC RiboZero      86.82           13.41                0.0015
3   S003  RunA RiboZero      99.47            7.88                0.0205
4   S004  RunC    PolyA      97.33           13.95                0.0283</code></pre>
</div>
</div>
</section>
<section id="overview-a-clustered-qc-heatmap" class="level2">
<h2 class="anchored" data-anchor-id="overview-a-clustered-qc-heatmap">Overview — a clustered QC heatmap</h2>
<p>Z-score each metric and cluster: outlier samples and any batch/library structure jump out at a glance. This is the “is anything wrong, and where” view.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">canvasXpress</span>(</span>
<span id="cb3-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">t</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale</span>(m)), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">smpAnnot =</span> annot,</span>
<span id="cb3-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">graphType =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Heatmap"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">samplesClustered =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">variablesClustered =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,</span>
<span id="cb3-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colorSpectrum =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"navy"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"white"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"firebrick3"</span>),</span>
<span id="cb3-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"QC metrics (z-scored) — 96 samples clustered"</span>,</span>
<span id="cb3-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">820</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">height =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">420</span></span>
<span id="cb3-7">)</span></code></pre></div>
<div class="cell-output-display">
<div id="htmlwidget-5499ac24958b2a2488c0" style="width:100%;height:332px;" class="canvasXpress html-widget"></div>
<script type="application/json" data-for="htmlwidget-5499ac24958b2a2488c0">{"x":{"data":{"y":{"vars":["total_reads","pct_mapped","pct_duplication","pct_q30","gc_content","insert_size","contamination_freemix"],"smps":["S001","S002","S003","S004","S005","S006","S007","S008","S009","S010","S011","S012","S013","S014","S015","S016","S017","S018","S019","S020","S021","S022","S023","S024","S025","S026","S027","S028","S029","S030","S031","S032","S033","S034","S035","S036","S037","S038","S039","S040","S041","S042","S043","S044","S045","S046","S047","S048","S049","S050","S051","S052","S053","S054","S055","S056","S057","S058","S059","S060","S061","S062","S063","S064","S065","S066","S067","S068","S069","S070","S071","S072","S073","S074","S075","S076","S077","S078","S079","S080","S081","S082","S083","S084","S085","S086","S087","S088","S089","S090","S091","S092","S093","S094","S095","S096"],"data":[[-0.2964,-0.225,-1.081,1.264,0.2511,-0.6403,0.4025,0.6116,-0.6655,0.9377,-0.9697,0.6836,0.7683,0.515,0.4857,-0.09071,1.825,0.19,0.5817,-0.6265,-1.054,1.834,0.2125,0.8722,-1.625,1.388,0.5647,-1.758,0.2143,-1.29,0.1956,-0.561,1.049,-0.7162,0.155,-1.941,-0.7575,1.014,-0.2371,2.17,-2.119,0.6232,-0.7022,1.048,-0.3286,-0.9531,0.3509,-0.3473,0.1289,-1.769,0.9221,-0.1832,0.537,0.1032,-0.2542,-2.206,-0.8424,1.007,0.09225,-0.9139,0.1777,-1.133,-1.386,0.5063,-1.406,0.5744,-1.033,0.9085,-0.5945,0.6695,-0.03324,0.6518,0.1814,-1.288,-0.836,-1.329,-0.8097,-0.4051,1.039,0.7179,1.193,0.8134,0.4248,2.997,1.026,-1.165,-0.4464,-0.5936,1.293,-0.5703,0.2211,0.9498,-1.347,0.7281,1.206,0.2512],[0.2887,-1.501,1.719,1.174,0.1411,0.2785,1.014,0.6476,0.9505,1.406,-0.6759,-0.5919,-0.02688,-0.6555,1.108,-1.676,0.04438,0.953,-0.7752,-0.7421,-3.486,1.248,-1.002,-0.5385,-1.096,0.04184,0.7672,0.6883,1.727,0.5178,-1.093,-0.3527,0.3142,-0.8235,-0.5945,0.3396,-0.7064,-0.7675,0.02911,0.3651,-1.022,0.1665,0.7952,1.174,-0.9584,0.1818,0.9479,-0.2916,1.612,-1.175,0.8792,0.4185,0.9021,0.7392,1.727,0.6578,-0.08542,0.388,0.9606,0.06474,-2.417,-0.3119,0.7698,-2.684,-1.865,1.727,0.2327,-0.05488,-0.1236,0.01638,-1.075,0.1895,0.2607,0.6883,-0.1541,-2.799,1.055,0.3193,-0.2458,-0.2178,0.1996,0.9734,-0.5181,0.4974,-0.1898,-0.541,0.2633,0.03166,-0.2559,0.1156,0.1131,0.36,-1.047,0.8741,-1.121,0.192],[-0.3825,-0.1534,-0.9925,-0.07146,-0.5069,-0.06539,0.8101,0.6781,-0.1716,2.243,0.08635,1.529,-0.3962,-0.6086,-1.363,1.306,0.5051,-1.458,-1.674,0.3155,1.725,-0.3689,1.393,-1.1,-1.747,-1.276,-0.6314,0.6645,-1.24,0.3079,-0.5798,1.064,-0.8438,1.464,-1.539,-0.06084,-0.8393,-0.3977,-0.5024,0.6918,0.3747,1.933,-0.8241,0.4111,-0.5676,-1.334,-0.4341,-0.4523,-0.5919,0.8466,-0.3749,1.203,-0.6374,0.2077,-1.208,-0.9166,-1.252,0.9998,-0.4144,-1.495,1.29,0.5886,-0.3051,2.569,2.61,-0.8757,0.1288,0.1592,-1.026,1.255,-0.2657,-1.134,-0.5434,0.9376,-0.3294,1.071,-0.5343,-0.337,0.9027,0.1121,-0.9682,0.04841,-0.07298,0.1926,-1.575,0.7692,-1.285,0.8359,-0.3719,0.7115,0.8981,1.789,1.155,0.09697,0.1288,0.08787],[-1.127,1.278,-0.5781,0.558,-0.08841,-0.201,-0.1668,0.2299,0.132,-0.8132,-1.949,0.3474,-0.06882,-0.2402,-0.7691,1.102,0.8763,-0.9699,-0.6565,0.2103,1.121,1.724,-1.626,-0.6369,0.4552,-0.1668,0.6021,1.905,-2.782,0.5335,-0.1717,0.2446,0.7245,0.1809,-0.0933,-0.2696,0.1124,-0.7985,-0.3578,0.323,0.2838,0.2299,0.5189,2.027,-0.4361,1.298,-0.2157,-0.7104,-1.523,1.327,-1.607,-0.1863,-1.259,-0.6712,-0.1961,-2.096,-0.8426,-1.337,0.3279,-1.651,1.709,-0.4459,0.416,-1.229,1.895,0.607,0.009539,-2.478,0.1858,-0.6712,-1.185,0.6217,1.2,-0.6565,0.8323,-0.9405,-0.3724,0.009539,0.558,0.6168,0.8421,0.9008,0.0879,-0.25,1.856,0.3181,0.7931,2.047,-0.2451,1.239,-0.5585,1.2,0.004642,-0.3284,0.7882,-0.7838],[-1.068,-0.4543,0.5953,-1.103,-0.7669,-0.475,-0.03569,0.1412,1.651,-0.9143,-0.9143,-0.0003071,-1.23,-0.1035,-1.678,1.197,-2.386,-0.3276,-1.787,1.049,-0.09171,1.256,0.1088,-0.2244,-0.6902,1.194,-0.1595,0.6424,-1.645,-0.03569,0.439,-0.9762,0.4213,-2.188,1.132,1.736,-0.9172,-0.4897,2.408,0.06161,-0.13,0.1117,-0.4986,-2.332,0.5451,0.008538,-0.006204,0.4007,-1.643,0.8871,-0.05043,-0.5575,0.1383,2.208,-0.8317,-0.2332,1.468,-1.321,-0.4131,1.008,-0.4013,0.2709,0.8842,-0.3718,0.4921,0.265,-2.335,-0.4809,1.444,-0.7374,1.556,1.347,0.2562,0.008538,0.4272,0.6277,1.176,-0.4426,-0.1153,-1.421,0.2267,0.6808,0.2739,0.9196,0.3535,0.212,0.02328,1.017,0.5333,1.347,-0.8848,0.4537,0.8046,0.3181,-1.197,0.3388],[0.5064,0.1073,0.2669,0.5331,2.05,0.8258,-2.022,-0.6112,0.0008316,0.9588,0.8258,0.3202,0.8524,-0.9572,-0.7975,-2.155,0.08066,-0.6644,1.039,0.1871,-0.1854,-1.037,0.7193,-0.1588,1.092,0.7459,-0.2919,-0.6911,-0.558,0.9322,1.012,1.225,-0.9306,-1.383,-0.6112,-0.3451,0.4532,0.7726,2.076,-1.463,-1.276,-3.379,-0.5048,-1.117,0.8524,-0.5846,0.7726,-0.2919,-0.2919,-0.7443,-1.33,1.81,1.385,-0.3717,-0.8241,-0.2387,-0.2919,-0.1056,1.252,0.1073,-0.6112,1.225,0.4798,-0.4782,-0.1056,-1.09,0.9854,-0.3451,0.7193,-1.037,-0.3185,0.6661,-0.1056,1.092,0.2403,-2.075,1.198,0.7992,0.8524,2.396,-0.05239,0.9588,-0.3451,-1.25,-1.09,0.3734,0.1605,-0.2121,-0.05239,-0.4782,-0.02578,-0.1056,-0.2387,0.3202,1.571,-1.569],[-0.1512,-1.451,0.1955,0.8715,1.4,0.6028,1.686,0.7935,-1.261,1.565,0.2735,0.8975,-0.6799,0.02212,-1.148,1.028,-1.191,-0.9399,0.2041,1.695,-0.6453,1.192,-0.9919,-1.105,1.478,-1.573,-1.226,1.747,0.9408,-1.252,1.79,-0.8793,1.799,-0.02988,-0.07322,-0.7666,0.7935,-1.122,-0.6366,-1.373,1.556,0.02212,-0.1946,-1.365,-0.8273,-1.096,0.05679,-0.03855,-0.8533,-1.538,-1.191,-0.3419,-1.035,-0.09922,-0.8186,-0.2899,1.123,1.08,0.7675,-0.9399,0.4035,-0.4719,-1.469,0.9928,1.6,-1.469,1.002,0.04812,0.7415,0.3601,-0.6973,1.513,-0.9139,-0.7319,-0.4632,-1.009,0.7935,0.5768,-0.09055,-0.7579,0.3688,0.8975,-0.4112,1.383,0.5248,1.236,-1.538,0.8975,1.236,-0.6626,-1.044,-0.1426,0.1175,0.9495,0.1781,-0.4026]]},"x":{"Lane":["L4","L5","L4","L1","L4","L7","L7","L4","L5","L7","L3","L1","L2","L1","L1","L3","L8","L2","L6","L8","L3","L5","L6","L8","L6","L2","L2","L4","L6","L8","L2","L1","L4","L1","L4","L4","L5","L7","L8","L8","L7","L6","L5","L8","L6","L5","L4","L1","L5","L5","L8","L7","L5","L5","L6","L8","L4","L1","L7","L7","L3","L7","L5","L3","L3","L8","L1","L7","L6","L4","L1","L8","L6","L5","L5","L3","L4","L7","L7","L2","L7","L1","L7","L8","L2","L2","L4","L5","L6","L2","L1","L8","L3","L2","L4","L8"],"Batch":["RunA","RunC","RunA","RunC","RunC","RunA","RunB","RunB","RunB","RunC","RunC","RunC","RunB","RunA","RunC","RunC","RunC","RunC","RunC","RunC","RunC","RunC","RunC","RunC","RunB","RunC","RunA","RunA","RunC","RunA","RunC","RunC","RunC","RunA","RunB","RunA","RunC","RunB","RunB","RunC","RunA","RunA","RunA","RunB","RunA","RunA","RunB","RunA","RunA","RunB","RunA","RunC","RunC","RunA","RunC","RunC","RunA","RunA","RunC","RunA","RunB","RunA","RunB","RunC","RunB","RunB","RunB","RunB","RunC","RunB","RunB","RunA","RunA","RunC","RunB","RunA","RunB","RunA","RunB","RunC","RunC","RunA","RunA","RunA","RunC","RunA","RunC","RunC","RunA","RunA","RunA","RunB","RunC","RunA","RunC","RunC"],"Library":["PolyA","RiboZero","RiboZero","PolyA","RiboZero","PolyA","RiboZero","RiboZero","Exome","PolyA","PolyA","RiboZero","Exome","RiboZero","RiboZero","RiboZero","Exome","RiboZero","PolyA","PolyA","Exome","RiboZero","RiboZero","RiboZero","RiboZero","RiboZero","RiboZero","Exome","PolyA","PolyA","Exome","RiboZero","Exome","PolyA","Exome","PolyA","PolyA","PolyA","RiboZero","RiboZero","RiboZero","RiboZero","Exome","PolyA","RiboZero","PolyA","Exome","Exome","PolyA","RiboZero","RiboZero","Exome","Exome","RiboZero","PolyA","Exome","PolyA","RiboZero","RiboZero","PolyA","RiboZero","Exome","RiboZero","PolyA","Exome","Exome","Exome","RiboZero","RiboZero","PolyA","RiboZero","Exome","Exome","RiboZero","PolyA","PolyA","PolyA","PolyA","PolyA","Exome","RiboZero","RiboZero","PolyA","Exome","PolyA","RiboZero","RiboZero","PolyA","RiboZero","RiboZero","RiboZero","Exome","PolyA","PolyA","Exome","Exome"]},"z":null},"config":{"graphType":"Heatmap","isR":true,"samplesClustered":true,"variablesClustered":true,"colorSpectrum":["navy","white","firebrick3"],"title":"QC metrics (z-scored) — 96 samples clustered"},"events":null,"afterRender":null},"evals":[],"jsHooks":[]}</script>
</div>
</div>
</section>
<section id="the-linked-triage-dashboard" class="level2">
<h2 class="anchored" data-anchor-id="the-linked-triage-dashboard">The linked triage dashboard</h2>
<p>Four panels over the <strong>same samples</strong>, all sharing <code>broadcastGroup = "qc"</code>. The sample is the unit, so each sample is a point (<code>varAnnot</code> carries its lane/batch/library). Select points in any panel — drag a box in a scatter, click a bar — and the same samples re-mark everywhere.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1">qc_panel <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(cfg, ...) {</span>
<span id="cb4-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">do.call</span>(canvasXpress, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> m, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">varAnnot =</span> annot,</span>
<span id="cb4-3">                               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">broadcast =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">broadcastGroup =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"qc"</span>), cfg, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(...)))</span>
<span id="cb4-4">}</span></code></pre></div>
</div>
<section id="mapping-rate-vs-duplication-the-triage-plot" class="level3">
<h3 class="anchored" data-anchor-id="mapping-rate-vs-duplication-the-triage-plot">1 — Mapping rate vs duplication (the triage plot)</h3>
<p>Bubble size is depth; failing libraries fall to the <strong>bottom-right</strong> (low mapping, high duplication). Lasso them here.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">qc_panel</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">graphType =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Scatter2D"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xAxis =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pct_duplication"</span>),</span>
<span id="cb5-2">              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yAxis =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pct_mapped"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colorBy =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Batch"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sizeBy =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"total_reads"</span>,</span>
<span id="cb5-3">              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Mapping rate vs duplication — select the bottom-right"</span>),</span>
<span id="cb5-4">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">640</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">height =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">360</span>)</span></code></pre></div>
<div class="cell-output-display">
<div id="htmlwidget-ce36bb04be8a05559609" style="width:100%;height:365px;" class="canvasXpress html-widget"></div>
<script type="application/json" data-for="htmlwidget-ce36bb04be8a05559609">{"x":{"data":{"y":{"vars":["S001","S002","S003","S004","S005","S006","S007","S008","S009","S010","S011","S012","S013","S014","S015","S016","S017","S018","S019","S020","S021","S022","S023","S024","S025","S026","S027","S028","S029","S030","S031","S032","S033","S034","S035","S036","S037","S038","S039","S040","S041","S042","S043","S044","S045","S046","S047","S048","S049","S050","S051","S052","S053","S054","S055","S056","S057","S058","S059","S060","S061","S062","S063","S064","S065","S066","S067","S068","S069","S070","S071","S072","S073","S074","S075","S076","S077","S078","S079","S080","S081","S082","S083","S084","S085","S086","S087","S088","S089","S090","S091","S092","S093","S094","S095","S096"],"smps":["total_reads","pct_mapped","pct_duplication","pct_q30","gc_content","insert_size","contamination_freemix"],"data":[[3.973e+07,93.85,11.9,89.58,44.63,295,0.0165],[4.038e+07,86.82,13.41,94.49,46.71,280,0.0015],[3.258e+07,99.47,7.88,90.7,50.27,286,0.0205],[5.394e+07,97.33,13.95,93.02,44.51,296,0.0283],[4.472e+07,93.27,11.08,91.7,45.65,353,0.0344],[3.66e+07,93.81,13.99,91.47,46.64,307,0.0252],[4.61e+07,96.7,19.76,91.54,48.13,200,0.0377],[4.8e+07,95.26,18.89,92.35,48.73,253,0.0274],[3.637e+07,96.45,13.29,92.15,53.85,276,0.0037],[5.097e+07,98.24,29.2,90.22,45.15,312,0.0363],[3.36e+07,90.06,14.99,87.9,45.15,307,0.0214],[4.866e+07,90.39,24.5,92.59,48.25,288,0.0286],[4.943e+07,92.61,11.81,91.74,44.08,308,0.0104],[4.712e+07,90.14,10.41,91.39,47.9,240,0.0185],[4.685e+07,97.07,5.44,90.31,42.56,246,0.005],[4.16e+07,86.13,23.03,94.13,52.31,195,0.0301],[5.905e+07,92.89,17.75,93.67,40.16,279,0.0045],[4.416e+07,96.46,4.81,89.9,47.14,251,0.0074],[4.773e+07,89.67,3.39,90.54,42.19,315,0.0206],[3.672e+07,89.8,16.5,92.31,51.81,283,0.0378],[3.283e+07,79.02,25.79,94.17,47.94,269,0.0108],[5.913e+07,97.62,11.99,95.4,52.51,237,0.032],[4.437e+07,88.78,23.6,88.56,48.62,303,0.0068],[5.037e+07,90.6,7.17,90.58,47.49,270,0.0055],[2.763e+07,88.41,2.91,92.81,45.91,317,0.0353],[5.507e+07,92.88,6.01,91.54,52.3,304,0.0001],[4.757e+07,95.73,10.26,93.11,47.71,265,0.0041],[2.642e+07,95.42,18.8,95.77,50.43,250,0.0384],[4.438e+07,99.5,6.25,86.2,42.67,255,0.0291],[3.068e+07,94.75,16.45,92.97,48.13,311,0.0038],[4.421e+07,88.42,10.6,91.53,49.74,314,0.0389],[3.732e+07,91.33,21.43,92.38,44.94,322,0.0081],[5.198e+07,93.95,8.86,93.36,49.68,241,0.039],[3.591e+07,89.48,24.07,92.25,40.83,224,0.0179],[4.384e+07,90.38,4.28,91.69,52.09,253,0.0174],[2.475e+07,94.05,14.02,91.33,54.14,263,0.0094],[3.553e+07,89.94,8.89,92.11,45.14,293,0.0274],[5.167e+07,89.7,11.8,90.25,46.59,305,0.0053],[4.027e+07,92.83,11.11,91.15,56.42,354,0.0109],[6.219e+07,94.15,18.98,92.54,48.46,221,0.0024],[2.313e+07,88.7,16.89,92.46,47.81,228,0.0362],[4.811e+07,93.37,27.16,92.35,48.63,149,0.0185],[3.604e+07,95.84,8.99,92.94,46.56,257,0.016],[5.198e+07,97.33,17.13,96.02,40.34,234,0.0025],[3.944e+07,88.95,10.68,90.99,50.1,308,0.0087],[3.375e+07,93.43,5.63,94.53,48.28,254,0.0056],[4.563e+07,96.44,11.56,91.44,48.23,305,0.0189],[3.927e+07,91.57,11.44,90.43,49.61,265,0.0178],[4.36e+07,99.05,10.52,88.77,42.68,265,0.0084],[2.632e+07,88.1,20,94.59,51.26,248,0.0005],[5.083e+07,96.17,11.95,88.6,48.08,226,0.0045],[4.076e+07,94.36,22.35,91.5,46.36,344,0.0143],[4.732e+07,96.26,10.22,89.31,48.72,328,0.0063],[4.337e+07,95.62,15.79,90.51,55.74,262,0.0171],[4.011e+07,99.5,6.46,91.48,45.43,245,0.0088],[2.234e+07,95.3,8.38,87.6,47.46,267,0.0149],[3.476e+07,92.38,6.17,90.16,53.23,265,0.0312],[5.16e+07,94.24,21.01,89.15,43.77,272,0.0307],[4.327e+07,96.49,11.69,92.55,46.85,323,0.0271],[3.411e+07,92.97,4.57,88.51,51.67,280,0.0074],[4.405e+07,83.22,22.92,95.37,46.89,253,0.0229],[3.211e+07,91.49,18.3,90.97,49.17,322,0.0128],[2.981e+07,95.74,12.41,92.73,51.25,294,0.0013],[4.704e+07,82.17,31.35,89.37,46.99,258,0.0297],[2.963e+07,85.39,31.62,95.75,49.92,272,0.0367],[4.766e+07,99.5,8.65,93.12,49.15,235,0.0013],[3.302e+07,93.63,15.27,91.9,40.33,313,0.0298],[5.07e+07,92.5,15.47,86.82,46.62,263,0.0188],[3.702e+07,92.23,7.66,92.26,53.15,303,0.0268],[4.853e+07,92.78,22.69,90.51,45.75,237,0.0224],[4.213e+07,88.49,12.67,89.46,53.53,264,0.0102],[4.837e+07,93.46,6.95,93.15,52.82,301,0.0357],[4.408e+07,93.74,10.84,94.33,49.12,272,0.0077],[3.07e+07,95.42,20.6,90.54,48.28,317,0.0098],[3.482e+07,92.11,12.25,93.58,49.7,285,0.0129],[3.033e+07,81.72,21.48,89.96,50.38,198,0.0066],[3.506e+07,96.86,10.9,91.12,52.24,321,0.0274],[3.874e+07,93.97,12.2,91.9,46.75,306,0.0249],[5.189e+07,91.75,20.37,93.02,47.86,308,0.0172],[4.897e+07,91.86,15.16,93.14,43.43,366,0.0095],[5.329e+07,93.5,8.04,93.6,49.02,274,0.0225],[4.984e+07,96.54,14.74,93.72,50.56,312,0.0286],[4.63e+07,90.68,13.94,92.06,49.18,263,0.0135],[6.972e+07,94.67,15.69,91.37,51.37,229,0.0342],[5.177e+07,91.97,4.04,95.67,49.45,235,0.0243],[3.182e+07,90.59,19.49,92.53,48.97,290,0.0325],[3.837e+07,93.75,5.95,93.5,48.33,282,0.0005],[3.702e+07,92.84,19.93,96.06,51.7,268,0.0286],[5.42e+07,91.71,11.97,91.38,50.06,274,0.0325],[3.724e+07,93.17,19.11,94.41,52.82,258,0.0106],[4.444e+07,93.16,20.34,90.74,45.25,275,0.0062],[5.108e+07,94.13,26.21,94.33,49.79,272,0.0166],[3.017e+07,88.6,22.03,91.89,50.98,267,0.0196],[4.906e+07,96.15,15.06,91.21,49.33,288,0.0292],[5.342e+07,88.31,15.27,93.49,44.19,335,0.0203],[4.472e+07,93.47,15,90.28,49.4,217,0.0136]]},"x":null,"z":{"Lane":["L4","L5","L4","L1","L4","L7","L7","L4","L5","L7","L3","L1","L2","L1","L1","L3","L8","L2","L6","L8","L3","L5","L6","L8","L6","L2","L2","L4","L6","L8","L2","L1","L4","L1","L4","L4","L5","L7","L8","L8","L7","L6","L5","L8","L6","L5","L4","L1","L5","L5","L8","L7","L5","L5","L6","L8","L4","L1","L7","L7","L3","L7","L5","L3","L3","L8","L1","L7","L6","L4","L1","L8","L6","L5","L5","L3","L4","L7","L7","L2","L7","L1","L7","L8","L2","L2","L4","L5","L6","L2","L1","L8","L3","L2","L4","L8"],"Batch":["RunA","RunC","RunA","RunC","RunC","RunA","RunB","RunB","RunB","RunC","RunC","RunC","RunB","RunA","RunC","RunC","RunC","RunC","RunC","RunC","RunC","RunC","RunC","RunC","RunB","RunC","RunA","RunA","RunC","RunA","RunC","RunC","RunC","RunA","RunB","RunA","RunC","RunB","RunB","RunC","RunA","RunA","RunA","RunB","RunA","RunA","RunB","RunA","RunA","RunB","RunA","RunC","RunC","RunA","RunC","RunC","RunA","RunA","RunC","RunA","RunB","RunA","RunB","RunC","RunB","RunB","RunB","RunB","RunC","RunB","RunB","RunA","RunA","RunC","RunB","RunA","RunB","RunA","RunB","RunC","RunC","RunA","RunA","RunA","RunC","RunA","RunC","RunC","RunA","RunA","RunA","RunB","RunC","RunA","RunC","RunC"],"Library":["PolyA","RiboZero","RiboZero","PolyA","RiboZero","PolyA","RiboZero","RiboZero","Exome","PolyA","PolyA","RiboZero","Exome","RiboZero","RiboZero","RiboZero","Exome","RiboZero","PolyA","PolyA","Exome","RiboZero","RiboZero","RiboZero","RiboZero","RiboZero","RiboZero","Exome","PolyA","PolyA","Exome","RiboZero","Exome","PolyA","Exome","PolyA","PolyA","PolyA","RiboZero","RiboZero","RiboZero","RiboZero","Exome","PolyA","RiboZero","PolyA","Exome","Exome","PolyA","RiboZero","RiboZero","Exome","Exome","RiboZero","PolyA","Exome","PolyA","RiboZero","RiboZero","PolyA","RiboZero","Exome","RiboZero","PolyA","Exome","Exome","Exome","RiboZero","RiboZero","PolyA","RiboZero","Exome","Exome","RiboZero","PolyA","PolyA","PolyA","PolyA","PolyA","Exome","RiboZero","RiboZero","PolyA","Exome","PolyA","RiboZero","RiboZero","PolyA","RiboZero","RiboZero","RiboZero","Exome","PolyA","PolyA","Exome","Exome"]}},"config":{"graphType":"Scatter2D","isR":true,"broadcast":true,"broadcastGroup":"qc","xAxis":["pct_duplication"],"yAxis":["pct_mapped"],"colorBy":"Batch","sizeBy":"total_reads","title":"Mapping rate vs duplication — select the bottom-right"},"events":null,"afterRender":null},"evals":[],"jsHooks":[]}</script>
</div>
</div>
</section>
<section id="contamination-vs-mapping" class="level3">
<h3 class="anchored" data-anchor-id="contamination-vs-mapping">2 — Contamination vs mapping</h3>
<div class="cell">
<div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">qc_panel</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">graphType =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Scatter2D"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xAxis =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pct_mapped"</span>),</span>
<span id="cb6-2">              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yAxis =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"contamination_freemix"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colorBy =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Batch"</span>,</span>
<span id="cb6-3">              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Contamination (freemix) vs mapping rate"</span>),</span>
<span id="cb6-4">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">640</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">height =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">360</span>)</span></code></pre></div>
<div class="cell-output-display">
<div id="htmlwidget-c05435084398fcea9ffd" style="width:100%;height:365px;" class="canvasXpress html-widget"></div>
<script type="application/json" data-for="htmlwidget-c05435084398fcea9ffd">{"x":{"data":{"y":{"vars":["S001","S002","S003","S004","S005","S006","S007","S008","S009","S010","S011","S012","S013","S014","S015","S016","S017","S018","S019","S020","S021","S022","S023","S024","S025","S026","S027","S028","S029","S030","S031","S032","S033","S034","S035","S036","S037","S038","S039","S040","S041","S042","S043","S044","S045","S046","S047","S048","S049","S050","S051","S052","S053","S054","S055","S056","S057","S058","S059","S060","S061","S062","S063","S064","S065","S066","S067","S068","S069","S070","S071","S072","S073","S074","S075","S076","S077","S078","S079","S080","S081","S082","S083","S084","S085","S086","S087","S088","S089","S090","S091","S092","S093","S094","S095","S096"],"smps":["total_reads","pct_mapped","pct_duplication","pct_q30","gc_content","insert_size","contamination_freemix"],"data":[[3.973e+07,93.85,11.9,89.58,44.63,295,0.0165],[4.038e+07,86.82,13.41,94.49,46.71,280,0.0015],[3.258e+07,99.47,7.88,90.7,50.27,286,0.0205],[5.394e+07,97.33,13.95,93.02,44.51,296,0.0283],[4.472e+07,93.27,11.08,91.7,45.65,353,0.0344],[3.66e+07,93.81,13.99,91.47,46.64,307,0.0252],[4.61e+07,96.7,19.76,91.54,48.13,200,0.0377],[4.8e+07,95.26,18.89,92.35,48.73,253,0.0274],[3.637e+07,96.45,13.29,92.15,53.85,276,0.0037],[5.097e+07,98.24,29.2,90.22,45.15,312,0.0363],[3.36e+07,90.06,14.99,87.9,45.15,307,0.0214],[4.866e+07,90.39,24.5,92.59,48.25,288,0.0286],[4.943e+07,92.61,11.81,91.74,44.08,308,0.0104],[4.712e+07,90.14,10.41,91.39,47.9,240,0.0185],[4.685e+07,97.07,5.44,90.31,42.56,246,0.005],[4.16e+07,86.13,23.03,94.13,52.31,195,0.0301],[5.905e+07,92.89,17.75,93.67,40.16,279,0.0045],[4.416e+07,96.46,4.81,89.9,47.14,251,0.0074],[4.773e+07,89.67,3.39,90.54,42.19,315,0.0206],[3.672e+07,89.8,16.5,92.31,51.81,283,0.0378],[3.283e+07,79.02,25.79,94.17,47.94,269,0.0108],[5.913e+07,97.62,11.99,95.4,52.51,237,0.032],[4.437e+07,88.78,23.6,88.56,48.62,303,0.0068],[5.037e+07,90.6,7.17,90.58,47.49,270,0.0055],[2.763e+07,88.41,2.91,92.81,45.91,317,0.0353],[5.507e+07,92.88,6.01,91.54,52.3,304,0.0001],[4.757e+07,95.73,10.26,93.11,47.71,265,0.0041],[2.642e+07,95.42,18.8,95.77,50.43,250,0.0384],[4.438e+07,99.5,6.25,86.2,42.67,255,0.0291],[3.068e+07,94.75,16.45,92.97,48.13,311,0.0038],[4.421e+07,88.42,10.6,91.53,49.74,314,0.0389],[3.732e+07,91.33,21.43,92.38,44.94,322,0.0081],[5.198e+07,93.95,8.86,93.36,49.68,241,0.039],[3.591e+07,89.48,24.07,92.25,40.83,224,0.0179],[4.384e+07,90.38,4.28,91.69,52.09,253,0.0174],[2.475e+07,94.05,14.02,91.33,54.14,263,0.0094],[3.553e+07,89.94,8.89,92.11,45.14,293,0.0274],[5.167e+07,89.7,11.8,90.25,46.59,305,0.0053],[4.027e+07,92.83,11.11,91.15,56.42,354,0.0109],[6.219e+07,94.15,18.98,92.54,48.46,221,0.0024],[2.313e+07,88.7,16.89,92.46,47.81,228,0.0362],[4.811e+07,93.37,27.16,92.35,48.63,149,0.0185],[3.604e+07,95.84,8.99,92.94,46.56,257,0.016],[5.198e+07,97.33,17.13,96.02,40.34,234,0.0025],[3.944e+07,88.95,10.68,90.99,50.1,308,0.0087],[3.375e+07,93.43,5.63,94.53,48.28,254,0.0056],[4.563e+07,96.44,11.56,91.44,48.23,305,0.0189],[3.927e+07,91.57,11.44,90.43,49.61,265,0.0178],[4.36e+07,99.05,10.52,88.77,42.68,265,0.0084],[2.632e+07,88.1,20,94.59,51.26,248,0.0005],[5.083e+07,96.17,11.95,88.6,48.08,226,0.0045],[4.076e+07,94.36,22.35,91.5,46.36,344,0.0143],[4.732e+07,96.26,10.22,89.31,48.72,328,0.0063],[4.337e+07,95.62,15.79,90.51,55.74,262,0.0171],[4.011e+07,99.5,6.46,91.48,45.43,245,0.0088],[2.234e+07,95.3,8.38,87.6,47.46,267,0.0149],[3.476e+07,92.38,6.17,90.16,53.23,265,0.0312],[5.16e+07,94.24,21.01,89.15,43.77,272,0.0307],[4.327e+07,96.49,11.69,92.55,46.85,323,0.0271],[3.411e+07,92.97,4.57,88.51,51.67,280,0.0074],[4.405e+07,83.22,22.92,95.37,46.89,253,0.0229],[3.211e+07,91.49,18.3,90.97,49.17,322,0.0128],[2.981e+07,95.74,12.41,92.73,51.25,294,0.0013],[4.704e+07,82.17,31.35,89.37,46.99,258,0.0297],[2.963e+07,85.39,31.62,95.75,49.92,272,0.0367],[4.766e+07,99.5,8.65,93.12,49.15,235,0.0013],[3.302e+07,93.63,15.27,91.9,40.33,313,0.0298],[5.07e+07,92.5,15.47,86.82,46.62,263,0.0188],[3.702e+07,92.23,7.66,92.26,53.15,303,0.0268],[4.853e+07,92.78,22.69,90.51,45.75,237,0.0224],[4.213e+07,88.49,12.67,89.46,53.53,264,0.0102],[4.837e+07,93.46,6.95,93.15,52.82,301,0.0357],[4.408e+07,93.74,10.84,94.33,49.12,272,0.0077],[3.07e+07,95.42,20.6,90.54,48.28,317,0.0098],[3.482e+07,92.11,12.25,93.58,49.7,285,0.0129],[3.033e+07,81.72,21.48,89.96,50.38,198,0.0066],[3.506e+07,96.86,10.9,91.12,52.24,321,0.0274],[3.874e+07,93.97,12.2,91.9,46.75,306,0.0249],[5.189e+07,91.75,20.37,93.02,47.86,308,0.0172],[4.897e+07,91.86,15.16,93.14,43.43,366,0.0095],[5.329e+07,93.5,8.04,93.6,49.02,274,0.0225],[4.984e+07,96.54,14.74,93.72,50.56,312,0.0286],[4.63e+07,90.68,13.94,92.06,49.18,263,0.0135],[6.972e+07,94.67,15.69,91.37,51.37,229,0.0342],[5.177e+07,91.97,4.04,95.67,49.45,235,0.0243],[3.182e+07,90.59,19.49,92.53,48.97,290,0.0325],[3.837e+07,93.75,5.95,93.5,48.33,282,0.0005],[3.702e+07,92.84,19.93,96.06,51.7,268,0.0286],[5.42e+07,91.71,11.97,91.38,50.06,274,0.0325],[3.724e+07,93.17,19.11,94.41,52.82,258,0.0106],[4.444e+07,93.16,20.34,90.74,45.25,275,0.0062],[5.108e+07,94.13,26.21,94.33,49.79,272,0.0166],[3.017e+07,88.6,22.03,91.89,50.98,267,0.0196],[4.906e+07,96.15,15.06,91.21,49.33,288,0.0292],[5.342e+07,88.31,15.27,93.49,44.19,335,0.0203],[4.472e+07,93.47,15,90.28,49.4,217,0.0136]]},"x":null,"z":{"Lane":["L4","L5","L4","L1","L4","L7","L7","L4","L5","L7","L3","L1","L2","L1","L1","L3","L8","L2","L6","L8","L3","L5","L6","L8","L6","L2","L2","L4","L6","L8","L2","L1","L4","L1","L4","L4","L5","L7","L8","L8","L7","L6","L5","L8","L6","L5","L4","L1","L5","L5","L8","L7","L5","L5","L6","L8","L4","L1","L7","L7","L3","L7","L5","L3","L3","L8","L1","L7","L6","L4","L1","L8","L6","L5","L5","L3","L4","L7","L7","L2","L7","L1","L7","L8","L2","L2","L4","L5","L6","L2","L1","L8","L3","L2","L4","L8"],"Batch":["RunA","RunC","RunA","RunC","RunC","RunA","RunB","RunB","RunB","RunC","RunC","RunC","RunB","RunA","RunC","RunC","RunC","RunC","RunC","RunC","RunC","RunC","RunC","RunC","RunB","RunC","RunA","RunA","RunC","RunA","RunC","RunC","RunC","RunA","RunB","RunA","RunC","RunB","RunB","RunC","RunA","RunA","RunA","RunB","RunA","RunA","RunB","RunA","RunA","RunB","RunA","RunC","RunC","RunA","RunC","RunC","RunA","RunA","RunC","RunA","RunB","RunA","RunB","RunC","RunB","RunB","RunB","RunB","RunC","RunB","RunB","RunA","RunA","RunC","RunB","RunA","RunB","RunA","RunB","RunC","RunC","RunA","RunA","RunA","RunC","RunA","RunC","RunC","RunA","RunA","RunA","RunB","RunC","RunA","RunC","RunC"],"Library":["PolyA","RiboZero","RiboZero","PolyA","RiboZero","PolyA","RiboZero","RiboZero","Exome","PolyA","PolyA","RiboZero","Exome","RiboZero","RiboZero","RiboZero","Exome","RiboZero","PolyA","PolyA","Exome","RiboZero","RiboZero","RiboZero","RiboZero","RiboZero","RiboZero","Exome","PolyA","PolyA","Exome","RiboZero","Exome","PolyA","Exome","PolyA","PolyA","PolyA","RiboZero","RiboZero","RiboZero","RiboZero","Exome","PolyA","RiboZero","PolyA","Exome","Exome","PolyA","RiboZero","RiboZero","Exome","Exome","RiboZero","PolyA","Exome","PolyA","RiboZero","RiboZero","PolyA","RiboZero","Exome","RiboZero","PolyA","Exome","Exome","Exome","RiboZero","RiboZero","PolyA","RiboZero","Exome","Exome","RiboZero","PolyA","PolyA","PolyA","PolyA","PolyA","Exome","RiboZero","RiboZero","PolyA","Exome","PolyA","RiboZero","RiboZero","PolyA","RiboZero","RiboZero","RiboZero","Exome","PolyA","PolyA","Exome","Exome"]}},"config":{"graphType":"Scatter2D","isR":true,"broadcast":true,"broadcastGroup":"qc","xAxis":["pct_mapped"],"yAxis":["contamination_freemix"],"colorBy":"Batch","title":"Contamination (freemix) vs mapping rate"},"events":null,"afterRender":null},"evals":[],"jsHooks":[]}</script>
</div>
</div>
</section>
<section id="q30-vs-gc-by-library-prep" class="level3">
<h3 class="anchored" data-anchor-id="q30-vs-gc-by-library-prep">3 — Q30 vs GC, by library prep</h3>
<div class="cell">
<div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">qc_panel</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">graphType =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Scatter2D"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xAxis =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"gc_content"</span>),</span>
<span id="cb7-2">              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yAxis =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pct_q30"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colorBy =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Library"</span>,</span>
<span id="cb7-3">              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Q30 vs GC content, coloured by library"</span>),</span>
<span id="cb7-4">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">640</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">height =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">360</span>)</span></code></pre></div>
<div class="cell-output-display">
<div id="htmlwidget-a9110a1bb34964137bfe" style="width:100%;height:365px;" class="canvasXpress html-widget"></div>
<script type="application/json" data-for="htmlwidget-a9110a1bb34964137bfe">{"x":{"data":{"y":{"vars":["S001","S002","S003","S004","S005","S006","S007","S008","S009","S010","S011","S012","S013","S014","S015","S016","S017","S018","S019","S020","S021","S022","S023","S024","S025","S026","S027","S028","S029","S030","S031","S032","S033","S034","S035","S036","S037","S038","S039","S040","S041","S042","S043","S044","S045","S046","S047","S048","S049","S050","S051","S052","S053","S054","S055","S056","S057","S058","S059","S060","S061","S062","S063","S064","S065","S066","S067","S068","S069","S070","S071","S072","S073","S074","S075","S076","S077","S078","S079","S080","S081","S082","S083","S084","S085","S086","S087","S088","S089","S090","S091","S092","S093","S094","S095","S096"],"smps":["total_reads","pct_mapped","pct_duplication","pct_q30","gc_content","insert_size","contamination_freemix"],"data":[[3.973e+07,93.85,11.9,89.58,44.63,295,0.0165],[4.038e+07,86.82,13.41,94.49,46.71,280,0.0015],[3.258e+07,99.47,7.88,90.7,50.27,286,0.0205],[5.394e+07,97.33,13.95,93.02,44.51,296,0.0283],[4.472e+07,93.27,11.08,91.7,45.65,353,0.0344],[3.66e+07,93.81,13.99,91.47,46.64,307,0.0252],[4.61e+07,96.7,19.76,91.54,48.13,200,0.0377],[4.8e+07,95.26,18.89,92.35,48.73,253,0.0274],[3.637e+07,96.45,13.29,92.15,53.85,276,0.0037],[5.097e+07,98.24,29.2,90.22,45.15,312,0.0363],[3.36e+07,90.06,14.99,87.9,45.15,307,0.0214],[4.866e+07,90.39,24.5,92.59,48.25,288,0.0286],[4.943e+07,92.61,11.81,91.74,44.08,308,0.0104],[4.712e+07,90.14,10.41,91.39,47.9,240,0.0185],[4.685e+07,97.07,5.44,90.31,42.56,246,0.005],[4.16e+07,86.13,23.03,94.13,52.31,195,0.0301],[5.905e+07,92.89,17.75,93.67,40.16,279,0.0045],[4.416e+07,96.46,4.81,89.9,47.14,251,0.0074],[4.773e+07,89.67,3.39,90.54,42.19,315,0.0206],[3.672e+07,89.8,16.5,92.31,51.81,283,0.0378],[3.283e+07,79.02,25.79,94.17,47.94,269,0.0108],[5.913e+07,97.62,11.99,95.4,52.51,237,0.032],[4.437e+07,88.78,23.6,88.56,48.62,303,0.0068],[5.037e+07,90.6,7.17,90.58,47.49,270,0.0055],[2.763e+07,88.41,2.91,92.81,45.91,317,0.0353],[5.507e+07,92.88,6.01,91.54,52.3,304,0.0001],[4.757e+07,95.73,10.26,93.11,47.71,265,0.0041],[2.642e+07,95.42,18.8,95.77,50.43,250,0.0384],[4.438e+07,99.5,6.25,86.2,42.67,255,0.0291],[3.068e+07,94.75,16.45,92.97,48.13,311,0.0038],[4.421e+07,88.42,10.6,91.53,49.74,314,0.0389],[3.732e+07,91.33,21.43,92.38,44.94,322,0.0081],[5.198e+07,93.95,8.86,93.36,49.68,241,0.039],[3.591e+07,89.48,24.07,92.25,40.83,224,0.0179],[4.384e+07,90.38,4.28,91.69,52.09,253,0.0174],[2.475e+07,94.05,14.02,91.33,54.14,263,0.0094],[3.553e+07,89.94,8.89,92.11,45.14,293,0.0274],[5.167e+07,89.7,11.8,90.25,46.59,305,0.0053],[4.027e+07,92.83,11.11,91.15,56.42,354,0.0109],[6.219e+07,94.15,18.98,92.54,48.46,221,0.0024],[2.313e+07,88.7,16.89,92.46,47.81,228,0.0362],[4.811e+07,93.37,27.16,92.35,48.63,149,0.0185],[3.604e+07,95.84,8.99,92.94,46.56,257,0.016],[5.198e+07,97.33,17.13,96.02,40.34,234,0.0025],[3.944e+07,88.95,10.68,90.99,50.1,308,0.0087],[3.375e+07,93.43,5.63,94.53,48.28,254,0.0056],[4.563e+07,96.44,11.56,91.44,48.23,305,0.0189],[3.927e+07,91.57,11.44,90.43,49.61,265,0.0178],[4.36e+07,99.05,10.52,88.77,42.68,265,0.0084],[2.632e+07,88.1,20,94.59,51.26,248,0.0005],[5.083e+07,96.17,11.95,88.6,48.08,226,0.0045],[4.076e+07,94.36,22.35,91.5,46.36,344,0.0143],[4.732e+07,96.26,10.22,89.31,48.72,328,0.0063],[4.337e+07,95.62,15.79,90.51,55.74,262,0.0171],[4.011e+07,99.5,6.46,91.48,45.43,245,0.0088],[2.234e+07,95.3,8.38,87.6,47.46,267,0.0149],[3.476e+07,92.38,6.17,90.16,53.23,265,0.0312],[5.16e+07,94.24,21.01,89.15,43.77,272,0.0307],[4.327e+07,96.49,11.69,92.55,46.85,323,0.0271],[3.411e+07,92.97,4.57,88.51,51.67,280,0.0074],[4.405e+07,83.22,22.92,95.37,46.89,253,0.0229],[3.211e+07,91.49,18.3,90.97,49.17,322,0.0128],[2.981e+07,95.74,12.41,92.73,51.25,294,0.0013],[4.704e+07,82.17,31.35,89.37,46.99,258,0.0297],[2.963e+07,85.39,31.62,95.75,49.92,272,0.0367],[4.766e+07,99.5,8.65,93.12,49.15,235,0.0013],[3.302e+07,93.63,15.27,91.9,40.33,313,0.0298],[5.07e+07,92.5,15.47,86.82,46.62,263,0.0188],[3.702e+07,92.23,7.66,92.26,53.15,303,0.0268],[4.853e+07,92.78,22.69,90.51,45.75,237,0.0224],[4.213e+07,88.49,12.67,89.46,53.53,264,0.0102],[4.837e+07,93.46,6.95,93.15,52.82,301,0.0357],[4.408e+07,93.74,10.84,94.33,49.12,272,0.0077],[3.07e+07,95.42,20.6,90.54,48.28,317,0.0098],[3.482e+07,92.11,12.25,93.58,49.7,285,0.0129],[3.033e+07,81.72,21.48,89.96,50.38,198,0.0066],[3.506e+07,96.86,10.9,91.12,52.24,321,0.0274],[3.874e+07,93.97,12.2,91.9,46.75,306,0.0249],[5.189e+07,91.75,20.37,93.02,47.86,308,0.0172],[4.897e+07,91.86,15.16,93.14,43.43,366,0.0095],[5.329e+07,93.5,8.04,93.6,49.02,274,0.0225],[4.984e+07,96.54,14.74,93.72,50.56,312,0.0286],[4.63e+07,90.68,13.94,92.06,49.18,263,0.0135],[6.972e+07,94.67,15.69,91.37,51.37,229,0.0342],[5.177e+07,91.97,4.04,95.67,49.45,235,0.0243],[3.182e+07,90.59,19.49,92.53,48.97,290,0.0325],[3.837e+07,93.75,5.95,93.5,48.33,282,0.0005],[3.702e+07,92.84,19.93,96.06,51.7,268,0.0286],[5.42e+07,91.71,11.97,91.38,50.06,274,0.0325],[3.724e+07,93.17,19.11,94.41,52.82,258,0.0106],[4.444e+07,93.16,20.34,90.74,45.25,275,0.0062],[5.108e+07,94.13,26.21,94.33,49.79,272,0.0166],[3.017e+07,88.6,22.03,91.89,50.98,267,0.0196],[4.906e+07,96.15,15.06,91.21,49.33,288,0.0292],[5.342e+07,88.31,15.27,93.49,44.19,335,0.0203],[4.472e+07,93.47,15,90.28,49.4,217,0.0136]]},"x":null,"z":{"Lane":["L4","L5","L4","L1","L4","L7","L7","L4","L5","L7","L3","L1","L2","L1","L1","L3","L8","L2","L6","L8","L3","L5","L6","L8","L6","L2","L2","L4","L6","L8","L2","L1","L4","L1","L4","L4","L5","L7","L8","L8","L7","L6","L5","L8","L6","L5","L4","L1","L5","L5","L8","L7","L5","L5","L6","L8","L4","L1","L7","L7","L3","L7","L5","L3","L3","L8","L1","L7","L6","L4","L1","L8","L6","L5","L5","L3","L4","L7","L7","L2","L7","L1","L7","L8","L2","L2","L4","L5","L6","L2","L1","L8","L3","L2","L4","L8"],"Batch":["RunA","RunC","RunA","RunC","RunC","RunA","RunB","RunB","RunB","RunC","RunC","RunC","RunB","RunA","RunC","RunC","RunC","RunC","RunC","RunC","RunC","RunC","RunC","RunC","RunB","RunC","RunA","RunA","RunC","RunA","RunC","RunC","RunC","RunA","RunB","RunA","RunC","RunB","RunB","RunC","RunA","RunA","RunA","RunB","RunA","RunA","RunB","RunA","RunA","RunB","RunA","RunC","RunC","RunA","RunC","RunC","RunA","RunA","RunC","RunA","RunB","RunA","RunB","RunC","RunB","RunB","RunB","RunB","RunC","RunB","RunB","RunA","RunA","RunC","RunB","RunA","RunB","RunA","RunB","RunC","RunC","RunA","RunA","RunA","RunC","RunA","RunC","RunC","RunA","RunA","RunA","RunB","RunC","RunA","RunC","RunC"],"Library":["PolyA","RiboZero","RiboZero","PolyA","RiboZero","PolyA","RiboZero","RiboZero","Exome","PolyA","PolyA","RiboZero","Exome","RiboZero","RiboZero","RiboZero","Exome","RiboZero","PolyA","PolyA","Exome","RiboZero","RiboZero","RiboZero","RiboZero","RiboZero","RiboZero","Exome","PolyA","PolyA","Exome","RiboZero","Exome","PolyA","Exome","PolyA","PolyA","PolyA","RiboZero","RiboZero","RiboZero","RiboZero","Exome","PolyA","RiboZero","PolyA","Exome","Exome","PolyA","RiboZero","RiboZero","Exome","Exome","RiboZero","PolyA","Exome","PolyA","RiboZero","RiboZero","PolyA","RiboZero","Exome","RiboZero","PolyA","Exome","Exome","Exome","RiboZero","RiboZero","PolyA","RiboZero","Exome","Exome","RiboZero","PolyA","PolyA","PolyA","PolyA","PolyA","Exome","RiboZero","RiboZero","PolyA","Exome","PolyA","RiboZero","RiboZero","PolyA","RiboZero","RiboZero","RiboZero","Exome","PolyA","PolyA","Exome","Exome"]}},"config":{"graphType":"Scatter2D","isR":true,"broadcast":true,"broadcastGroup":"qc","xAxis":["gc_content"],"yAxis":["pct_q30"],"colorBy":"Library","title":"Q30 vs GC content, coloured by library"},"events":null,"afterRender":null},"evals":[],"jsHooks":[]}</script>
</div>
</div>
</section>
<section id="sequencing-depth-per-sample" class="level3">
<h3 class="anchored" data-anchor-id="sequencing-depth-per-sample">4 — Sequencing depth per sample</h3>
<div class="cell">
<div class="sourceCode cell-code" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">qc_panel</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">graphType =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Bar"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">graphOrientation =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"vertical"</span>,</span>
<span id="cb8-2">              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xAxis =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"total_reads"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colorBy =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Batch"</span>,</span>
<span id="cb8-3">              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total reads per sample (flag the short ones)"</span>),</span>
<span id="cb8-4">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">820</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">height =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">300</span>)</span></code></pre></div>
<div class="cell-output-display">
<div id="htmlwidget-e3f3b3288326da57f797" style="width:100%;height:237px;" class="canvasXpress html-widget"></div>
<script type="application/json" data-for="htmlwidget-e3f3b3288326da57f797">{"x":{"data":{"y":{"vars":["S001","S002","S003","S004","S005","S006","S007","S008","S009","S010","S011","S012","S013","S014","S015","S016","S017","S018","S019","S020","S021","S022","S023","S024","S025","S026","S027","S028","S029","S030","S031","S032","S033","S034","S035","S036","S037","S038","S039","S040","S041","S042","S043","S044","S045","S046","S047","S048","S049","S050","S051","S052","S053","S054","S055","S056","S057","S058","S059","S060","S061","S062","S063","S064","S065","S066","S067","S068","S069","S070","S071","S072","S073","S074","S075","S076","S077","S078","S079","S080","S081","S082","S083","S084","S085","S086","S087","S088","S089","S090","S091","S092","S093","S094","S095","S096"],"smps":["total_reads","pct_mapped","pct_duplication","pct_q30","gc_content","insert_size","contamination_freemix"],"data":[[3.973e+07,93.85,11.9,89.58,44.63,295,0.0165],[4.038e+07,86.82,13.41,94.49,46.71,280,0.0015],[3.258e+07,99.47,7.88,90.7,50.27,286,0.0205],[5.394e+07,97.33,13.95,93.02,44.51,296,0.0283],[4.472e+07,93.27,11.08,91.7,45.65,353,0.0344],[3.66e+07,93.81,13.99,91.47,46.64,307,0.0252],[4.61e+07,96.7,19.76,91.54,48.13,200,0.0377],[4.8e+07,95.26,18.89,92.35,48.73,253,0.0274],[3.637e+07,96.45,13.29,92.15,53.85,276,0.0037],[5.097e+07,98.24,29.2,90.22,45.15,312,0.0363],[3.36e+07,90.06,14.99,87.9,45.15,307,0.0214],[4.866e+07,90.39,24.5,92.59,48.25,288,0.0286],[4.943e+07,92.61,11.81,91.74,44.08,308,0.0104],[4.712e+07,90.14,10.41,91.39,47.9,240,0.0185],[4.685e+07,97.07,5.44,90.31,42.56,246,0.005],[4.16e+07,86.13,23.03,94.13,52.31,195,0.0301],[5.905e+07,92.89,17.75,93.67,40.16,279,0.0045],[4.416e+07,96.46,4.81,89.9,47.14,251,0.0074],[4.773e+07,89.67,3.39,90.54,42.19,315,0.0206],[3.672e+07,89.8,16.5,92.31,51.81,283,0.0378],[3.283e+07,79.02,25.79,94.17,47.94,269,0.0108],[5.913e+07,97.62,11.99,95.4,52.51,237,0.032],[4.437e+07,88.78,23.6,88.56,48.62,303,0.0068],[5.037e+07,90.6,7.17,90.58,47.49,270,0.0055],[2.763e+07,88.41,2.91,92.81,45.91,317,0.0353],[5.507e+07,92.88,6.01,91.54,52.3,304,0.0001],[4.757e+07,95.73,10.26,93.11,47.71,265,0.0041],[2.642e+07,95.42,18.8,95.77,50.43,250,0.0384],[4.438e+07,99.5,6.25,86.2,42.67,255,0.0291],[3.068e+07,94.75,16.45,92.97,48.13,311,0.0038],[4.421e+07,88.42,10.6,91.53,49.74,314,0.0389],[3.732e+07,91.33,21.43,92.38,44.94,322,0.0081],[5.198e+07,93.95,8.86,93.36,49.68,241,0.039],[3.591e+07,89.48,24.07,92.25,40.83,224,0.0179],[4.384e+07,90.38,4.28,91.69,52.09,253,0.0174],[2.475e+07,94.05,14.02,91.33,54.14,263,0.0094],[3.553e+07,89.94,8.89,92.11,45.14,293,0.0274],[5.167e+07,89.7,11.8,90.25,46.59,305,0.0053],[4.027e+07,92.83,11.11,91.15,56.42,354,0.0109],[6.219e+07,94.15,18.98,92.54,48.46,221,0.0024],[2.313e+07,88.7,16.89,92.46,47.81,228,0.0362],[4.811e+07,93.37,27.16,92.35,48.63,149,0.0185],[3.604e+07,95.84,8.99,92.94,46.56,257,0.016],[5.198e+07,97.33,17.13,96.02,40.34,234,0.0025],[3.944e+07,88.95,10.68,90.99,50.1,308,0.0087],[3.375e+07,93.43,5.63,94.53,48.28,254,0.0056],[4.563e+07,96.44,11.56,91.44,48.23,305,0.0189],[3.927e+07,91.57,11.44,90.43,49.61,265,0.0178],[4.36e+07,99.05,10.52,88.77,42.68,265,0.0084],[2.632e+07,88.1,20,94.59,51.26,248,0.0005],[5.083e+07,96.17,11.95,88.6,48.08,226,0.0045],[4.076e+07,94.36,22.35,91.5,46.36,344,0.0143],[4.732e+07,96.26,10.22,89.31,48.72,328,0.0063],[4.337e+07,95.62,15.79,90.51,55.74,262,0.0171],[4.011e+07,99.5,6.46,91.48,45.43,245,0.0088],[2.234e+07,95.3,8.38,87.6,47.46,267,0.0149],[3.476e+07,92.38,6.17,90.16,53.23,265,0.0312],[5.16e+07,94.24,21.01,89.15,43.77,272,0.0307],[4.327e+07,96.49,11.69,92.55,46.85,323,0.0271],[3.411e+07,92.97,4.57,88.51,51.67,280,0.0074],[4.405e+07,83.22,22.92,95.37,46.89,253,0.0229],[3.211e+07,91.49,18.3,90.97,49.17,322,0.0128],[2.981e+07,95.74,12.41,92.73,51.25,294,0.0013],[4.704e+07,82.17,31.35,89.37,46.99,258,0.0297],[2.963e+07,85.39,31.62,95.75,49.92,272,0.0367],[4.766e+07,99.5,8.65,93.12,49.15,235,0.0013],[3.302e+07,93.63,15.27,91.9,40.33,313,0.0298],[5.07e+07,92.5,15.47,86.82,46.62,263,0.0188],[3.702e+07,92.23,7.66,92.26,53.15,303,0.0268],[4.853e+07,92.78,22.69,90.51,45.75,237,0.0224],[4.213e+07,88.49,12.67,89.46,53.53,264,0.0102],[4.837e+07,93.46,6.95,93.15,52.82,301,0.0357],[4.408e+07,93.74,10.84,94.33,49.12,272,0.0077],[3.07e+07,95.42,20.6,90.54,48.28,317,0.0098],[3.482e+07,92.11,12.25,93.58,49.7,285,0.0129],[3.033e+07,81.72,21.48,89.96,50.38,198,0.0066],[3.506e+07,96.86,10.9,91.12,52.24,321,0.0274],[3.874e+07,93.97,12.2,91.9,46.75,306,0.0249],[5.189e+07,91.75,20.37,93.02,47.86,308,0.0172],[4.897e+07,91.86,15.16,93.14,43.43,366,0.0095],[5.329e+07,93.5,8.04,93.6,49.02,274,0.0225],[4.984e+07,96.54,14.74,93.72,50.56,312,0.0286],[4.63e+07,90.68,13.94,92.06,49.18,263,0.0135],[6.972e+07,94.67,15.69,91.37,51.37,229,0.0342],[5.177e+07,91.97,4.04,95.67,49.45,235,0.0243],[3.182e+07,90.59,19.49,92.53,48.97,290,0.0325],[3.837e+07,93.75,5.95,93.5,48.33,282,0.0005],[3.702e+07,92.84,19.93,96.06,51.7,268,0.0286],[5.42e+07,91.71,11.97,91.38,50.06,274,0.0325],[3.724e+07,93.17,19.11,94.41,52.82,258,0.0106],[4.444e+07,93.16,20.34,90.74,45.25,275,0.0062],[5.108e+07,94.13,26.21,94.33,49.79,272,0.0166],[3.017e+07,88.6,22.03,91.89,50.98,267,0.0196],[4.906e+07,96.15,15.06,91.21,49.33,288,0.0292],[5.342e+07,88.31,15.27,93.49,44.19,335,0.0203],[4.472e+07,93.47,15,90.28,49.4,217,0.0136]]},"x":null,"z":{"Lane":["L4","L5","L4","L1","L4","L7","L7","L4","L5","L7","L3","L1","L2","L1","L1","L3","L8","L2","L6","L8","L3","L5","L6","L8","L6","L2","L2","L4","L6","L8","L2","L1","L4","L1","L4","L4","L5","L7","L8","L8","L7","L6","L5","L8","L6","L5","L4","L1","L5","L5","L8","L7","L5","L5","L6","L8","L4","L1","L7","L7","L3","L7","L5","L3","L3","L8","L1","L7","L6","L4","L1","L8","L6","L5","L5","L3","L4","L7","L7","L2","L7","L1","L7","L8","L2","L2","L4","L5","L6","L2","L1","L8","L3","L2","L4","L8"],"Batch":["RunA","RunC","RunA","RunC","RunC","RunA","RunB","RunB","RunB","RunC","RunC","RunC","RunB","RunA","RunC","RunC","RunC","RunC","RunC","RunC","RunC","RunC","RunC","RunC","RunB","RunC","RunA","RunA","RunC","RunA","RunC","RunC","RunC","RunA","RunB","RunA","RunC","RunB","RunB","RunC","RunA","RunA","RunA","RunB","RunA","RunA","RunB","RunA","RunA","RunB","RunA","RunC","RunC","RunA","RunC","RunC","RunA","RunA","RunC","RunA","RunB","RunA","RunB","RunC","RunB","RunB","RunB","RunB","RunC","RunB","RunB","RunA","RunA","RunC","RunB","RunA","RunB","RunA","RunB","RunC","RunC","RunA","RunA","RunA","RunC","RunA","RunC","RunC","RunA","RunA","RunA","RunB","RunC","RunA","RunC","RunC"],"Library":["PolyA","RiboZero","RiboZero","PolyA","RiboZero","PolyA","RiboZero","RiboZero","Exome","PolyA","PolyA","RiboZero","Exome","RiboZero","RiboZero","RiboZero","Exome","RiboZero","PolyA","PolyA","Exome","RiboZero","RiboZero","RiboZero","RiboZero","RiboZero","RiboZero","Exome","PolyA","PolyA","Exome","RiboZero","Exome","PolyA","Exome","PolyA","PolyA","PolyA","RiboZero","RiboZero","RiboZero","RiboZero","Exome","PolyA","RiboZero","PolyA","Exome","Exome","PolyA","RiboZero","RiboZero","Exome","Exome","RiboZero","PolyA","Exome","PolyA","RiboZero","RiboZero","PolyA","RiboZero","Exome","RiboZero","PolyA","Exome","Exome","Exome","RiboZero","RiboZero","PolyA","RiboZero","Exome","Exome","RiboZero","PolyA","PolyA","PolyA","PolyA","PolyA","Exome","RiboZero","RiboZero","PolyA","Exome","PolyA","RiboZero","RiboZero","PolyA","RiboZero","RiboZero","RiboZero","Exome","PolyA","PolyA","Exome","Exome"]}},"config":{"graphType":"Bar","isR":true,"broadcast":true,"broadcastGroup":"qc","graphOrientation":"vertical","xAxis":["total_reads"],"colorBy":"Batch","title":"Total reads per sample (flag the short ones)"},"events":null,"afterRender":null},"evals":[],"jsHooks":[]}</script>
</div>
</div>
<p>Put the four panels on one page (this document, a Shiny app, a flex layout). Lasso the bad cluster in panel 1 and panels 2–4 immediately restrict to those samples — you can read their contamination, their library, and their depth without a single callback. The “wiring” is one shared group id.</p>
</section>
</section>
<section id="why-reproducible" class="level2">
<h2 class="anchored" data-anchor-id="why-reproducible">Why “reproducible”</h2>
<p>Each panel is a portable <code>data</code> + <code>config</code> spec; the cross-filter is just a shared <code>broadcastGroup</code>. The same specs reproduce the dashboard from Python or JavaScript, against the same <code>ngs-qc.csv</code>.</p>
</section>
<section id="next" class="level2">
<h2 class="anchored" data-anchor-id="next">Next</h2>
<ul>
<li><a href="../network-graphs-in-r/">Interactive network graphs in R</a></li>
<li>Gallery: <a href="https://canvasxpress.org/examples.html" class="uri">https://canvasxpress.org/examples.html</a></li>
<li>Package: <a href="https://github.com/neuhausi/canvasXpress" class="uri">https://github.com/neuhausi/canvasXpress</a></li>
</ul>


</section>

 ]]></description>
  <category>R</category>
  <category>canvasXpress</category>
  <category>dashboard</category>
  <category>bioinformatics</category>
  <category>visualization</category>
  <guid>https://neuhausi.github.io/canvasxpress-blog/posts/r/linked-dashboards-in-r/</guid>
  <pubDate>Thu, 29 Oct 2026 04:00:00 GMT</pubDate>
  <media:content url="https://neuhausi.github.io/canvasxpress-blog/posts/r/linked-dashboards-in-r/thumbnail.png" medium="image" type="image/png" height="110" width="144"/>
</item>
<item>
  <title>Genome browser tracks in R with canvasXpress</title>
  <dc:creator>Isaac Neuhaus</dc:creator>
  <link>https://neuhausi.github.io/canvasxpress-blog/posts/r/genome-tracks-in-r/</link>
  <description><![CDATA[ 




<p>A genome browser view stacks <strong>tracks</strong> that share one coordinate axis: coverage, gene models, variants. In R this usually means <code>Gviz</code> or <code>ggbio</code>. Here we build an interactive, zoomable view with <a href="https://canvasxpress.org">canvasXpress</a> — and the whole thing is one portable spec.</p>
<section id="the-data-shape" class="level2">
<h2 class="anchored" data-anchor-id="the-data-shape">The data shape</h2>
<p>A Genome figure is a list of <strong>tracks</strong> that share one coordinate axis — each with a <code>type</code>. Real browser views stack several: here we build four — <strong>gene models</strong> (<code>box</code>, multi-exon, connected), <strong>coverage across three tissues</strong> (<code>bar</code>), an <strong>expression heatmap</strong> (<code>heatmap</code>), and <strong>variant markers</strong> (<code>triangle</code>).</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(canvasXpress)</span>
<span id="cb1-2"></span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set.seed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span>
<span id="cb1-4"></span>
<span id="cb1-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Gene models: each gene is a set of exon [start, end] intervals, drawn connected.</span></span>
<span id="cb1-6">genes <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(j) {</span>
<span id="cb1-7">  start <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">40</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> j <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">120</span></span>
<span id="cb1-8">  exons <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>), <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(k) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(start <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> k <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>, start <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> k <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">18</span>))</span>
<span id="cb1-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">id =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"GENE"</span>, j <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dir =</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (j <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%%</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"right"</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"left"</span>,</span>
<span id="cb1-10">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rgb(70,130,220)"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">outline =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rgb(0,0,0)"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> exons)</span>
<span id="cb1-11">})</span>
<span id="cb1-12"></span>
<span id="cb1-13"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Coverage and expression: one entry per binned position, three tissues each.</span></span>
<span id="cb1-14">offsets  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">21</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">22</span></span>
<span id="cb1-15">coverage <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq_along</span>(offsets), <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(i)</span>
<span id="cb1-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">id =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"p"</span>, i), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">offset =</span> offsets[i],</span>
<span id="cb1-17">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">45</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">45</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">45</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))))</span>
<span id="cb1-18">express  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq_along</span>(offsets), <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(i)</span>
<span id="cb1-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">id =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"p"</span>, i), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">offset =</span> offsets[i],</span>
<span id="cb1-20">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rnorm</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rnorm</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rnorm</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>))))</span>
<span id="cb1-21"></span>
<span id="cb1-22"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Variants: point markers at genomic positions.</span></span>
<span id="cb1-23">snps <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(k)</span>
<span id="cb1-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">id =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rs"</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> k), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">offset =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">45</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">520</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>),</span>
<span id="cb1-25">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rgb(200,40,40)"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">outline =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rgb(0,0,0)"</span>))</span>
<span id="cb1-26"></span>
<span id="cb1-27">genome <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">tracks =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(</span>
<span id="cb1-28">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">name =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Genes (exon models)"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"box"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">connect =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> genes),</span>
<span id="cb1-29">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">name =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Coverage — Heart / Liver / Kidney"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bar"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">height =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">120</span>,</span>
<span id="cb1-30">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rgb(80,80,200)"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">outline =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rgb(60,60,60)"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> coverage),</span>
<span id="cb1-31">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">name =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Expression (z-score)"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"heatmap"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">height =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">90</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> express),</span>
<span id="cb1-32">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">name =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"SNPs"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"triangle"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> snps)</span>
<span id="cb1-33">))</span></code></pre></div>
</div>
</section>
<section id="the-plot" class="level2">
<h2 class="anchored" data-anchor-id="the-plot">The plot</h2>
<p>The Genome graph type is passed through to the engine as-is; <code>featureStaggered</code> spreads crowded features so labels stay legible.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">canvasXpress</span>(</span>
<span id="cb2-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data            =</span> genome,</span>
<span id="cb2-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">graphType       =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Genome"</span>,</span>
<span id="cb2-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">background       =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rgb(245,245,245)"</span>,</span>
<span id="cb2-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">featureStaggered =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,</span>
<span id="cb2-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title            =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Multi-track genome browser: genes, coverage, expression and variants"</span>,</span>
<span id="cb2-7">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width            =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">760</span>,</span>
<span id="cb2-8">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">height           =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">520</span></span>
<span id="cb2-9">)</span></code></pre></div>
<div class="cell-output cell-output-stderr">
<pre><code>The Genome graphType is an advanced chart, data is passed as-is to the JS library</code></pre>
</div>
<div class="cell-output-display">
<div id="htmlwidget-8950278926928da8d023" style="width:100%;height:444px;" class="canvasXpress html-widget"></div>
<script type="application/json" data-for="htmlwidget-8950278926928da8d023">{"x":{"data":{"tracks":[{"name":"Genes (exon models)","type":"box","connect":true,"data":[{"id":"GENE1","dir":"right","fill":"rgb(70,130,220)","outline":"rgb(0,0,0)","data":[[40,58],[70,88]]},{"id":"GENE2","dir":"left","fill":"rgb(70,130,220)","outline":"rgb(0,0,0)","data":[[160,178],[190,208],[220,238]]},{"id":"GENE3","dir":"right","fill":"rgb(70,130,220)","outline":"rgb(0,0,0)","data":[[280,298],[310,328],[340,358],[370,388]]},{"id":"GENE4","dir":"left","fill":"rgb(70,130,220)","outline":"rgb(0,0,0)","data":[[400,418],[430,448],[460,478]]}]},{"name":"Coverage — Heart / Liver / Kidney","type":"bar","height":120,"fill":"rgb(80,80,200)","outline":"rgb(60,60,60)","data":[{"id":"p1","offset":50,"data":[38,15,27]},{"id":"p2","offset":72,"data":[17,15,44]},{"id":"p3","offset":94,"data":[9,36,12]},{"id":"p4","offset":116,"data":[44,16,16]},{"id":"p5","offset":138,"data":[25,23,32]},{"id":"p6","offset":160,"data":[19,29,13]},{"id":"p7","offset":182,"data":[22,17,18]},{"id":"p8","offset":204,"data":[36,30,10]},{"id":"p9","offset":226,"data":[44,15,17]},{"id":"p10","offset":248,"data":[11,40,26]},{"id":"p11","offset":270,"data":[45,33,14]},{"id":"p12","offset":292,"data":[8,16,12]},{"id":"p13","offset":314,"data":[13,38,43]},{"id":"p14","offset":336,"data":[21,16,10]},{"id":"p15","offset":358,"data":[11,19,24]},{"id":"p16","offset":380,"data":[43,45,40]},{"id":"p17","offset":402,"data":[20,9,9]},{"id":"p18","offset":424,"data":[31,14,17]},{"id":"p19","offset":446,"data":[45,26,40]},{"id":"p20","offset":468,"data":[17,9,18]},{"id":"p21","offset":490,"data":[33,11,23]},{"id":"p22","offset":512,"data":[13,30,14]}]},{"name":"Expression (z-score)","type":"heatmap","height":90,"data":[{"id":"p1","offset":50,"data":[0.92,-0.79,0.57]},{"id":"p2","offset":72,"data":[0.92,0.26,0.35]},{"id":"p3","offset":94,"data":[1.17,-0.48,-0.42]},{"id":"p4","offset":116,"data":[0.96,-1.29,0.19]},{"id":"p5","offset":138,"data":[-0.03,0.47,1.02]},{"id":"p6","offset":160,"data":[0.27,0.23,0.75]},{"id":"p7","offset":182,"data":[1.22,0.38,-0.99]},{"id":"p8","offset":204,"data":[-0.16,1.74,-0.35]},{"id":"p9","offset":226,"data":[0.6899999999999999,1.22,0.79]},{"id":"p10","offset":248,"data":[-0.01,0.22,-0.89]},{"id":"p11","offset":270,"data":[0.44,-0.89,-0.85]},{"id":"p12","offset":292,"data":[-0.99,-0.65,1.05]},{"id":"p13","offset":314,"data":[-0.39,-0.07000000000000001,-0.46]},{"id":"p14","offset":336,"data":[0.54,0.93,-0.21]},{"id":"p15","offset":358,"data":[0.62,-0.41,1.05]},{"id":"p16","offset":380,"data":[0.6,1.02,0.61]},{"id":"p17","offset":402,"data":[0.21,-1.9,-0.68]},{"id":"p18","offset":424,"data":[0.48,-0.46,-0.28]},{"id":"p19","offset":446,"data":[-0.41,1.62,-0.72]},{"id":"p20","offset":468,"data":[-0.45,0.01,0.22]},{"id":"p21","offset":490,"data":[0.19,-0.05,-1.5]},{"id":"p22","offset":512,"data":[0.37,0.52,-0.48]}]},{"name":"SNPs","type":"triangle","data":[{"id":"rs1000","offset":52,"fill":"rgb(200,40,40)","outline":"rgb(0,0,0)"},{"id":"rs1001","offset":158,"fill":"rgb(200,40,40)","outline":"rgb(0,0,0)"},{"id":"rs1002","offset":316,"fill":"rgb(200,40,40)","outline":"rgb(0,0,0)"},{"id":"rs1003","offset":387,"fill":"rgb(200,40,40)","outline":"rgb(0,0,0)"},{"id":"rs1004","offset":165,"fill":"rgb(200,40,40)","outline":"rgb(0,0,0)"},{"id":"rs1005","offset":50,"fill":"rgb(200,40,40)","outline":"rgb(0,0,0)"},{"id":"rs1006","offset":264,"fill":"rgb(200,40,40)","outline":"rgb(0,0,0)"},{"id":"rs1007","offset":252,"fill":"rgb(200,40,40)","outline":"rgb(0,0,0)"},{"id":"rs1008","offset":258,"fill":"rgb(200,40,40)","outline":"rgb(0,0,0)"}]}]},"config":{"graphType":"Genome","isR":true,"background":"rgb(245,245,245)","featureStaggered":true,"title":"Multi-track genome browser: genes, coverage, expression and variants"},"events":null,"afterRender":null},"evals":[],"jsHooks":[]}</script>
</div>
</div>
<p>Scroll/drag to pan and zoom into a region; every track stays locked to the shared coordinate axis, so the gene models, coverage, expression and variants line up position-for-position. Swap each track for your own pileup, annotation and VCF-derived data.</p>
</section>
<section id="why-reproducible" class="level2">
<h2 class="anchored" data-anchor-id="why-reproducible">Why “reproducible”</h2>
<p>The tracks and <code>config</code> <strong>are</strong> the figure — one portable spec that renders the identical browser view from Python or JavaScript, and can be validated and re-rendered later.</p>
</section>
<section id="next" class="level2">
<h2 class="anchored" data-anchor-id="next">Next</h2>
<ul>
<li><a href="../network-graphs-in-r/">Interactive network graphs in R</a></li>
<li>Gallery: <a href="https://canvasxpress.org/examples.html" class="uri">https://canvasxpress.org/examples.html</a></li>
<li>Package: <a href="https://github.com/neuhausi/canvasXpress" class="uri">https://github.com/neuhausi/canvasXpress</a></li>
</ul>


</section>

 ]]></description>
  <category>R</category>
  <category>canvasXpress</category>
  <category>genome</category>
  <category>bioinformatics</category>
  <category>visualization</category>
  <guid>https://neuhausi.github.io/canvasxpress-blog/posts/r/genome-tracks-in-r/</guid>
  <pubDate>Thu, 29 Oct 2026 04:00:00 GMT</pubDate>
  <media:content url="https://neuhausi.github.io/canvasxpress-blog/posts/r/genome-tracks-in-r/thumbnail.png" medium="image" type="image/png" height="272" width="144"/>
</item>
<item>
  <title>Oncoprints (mutation landscapes) in R with canvasXpress</title>
  <dc:creator>Isaac Neuhaus</dc:creator>
  <link>https://neuhausi.github.io/canvasxpress-blog/posts/r/oncoprint-in-r/</link>
  <description><![CDATA[ 




<p>An oncoprint is the standard way to show a <strong>mutation landscape</strong>: genes down one axis, tumours along the other, each cell stacking the alterations that gene carries in that sample — copy-number amplification/deletion plus mutation type — with per-gene (or per-sample) frequencies alongside. In R the usual tool is <code>ComplexHeatmap::oncoPrint</code>. Here we build an interactive one with <a href="https://canvasxpress.org">canvasXpress</a>, from a single portable spec.</p>
<section id="the-data-shape" class="level2">
<h2 class="anchored" data-anchor-id="the-data-shape">The data shape</h2>
<p>An oncoprint is a <code>Heatmap</code> with <strong>overlay matrices</strong>: a base matrix (<code>y</code>, here expression) plus same-shaped layers for copy-number (<code>data2</code>) and mutation (<code>data3</code>). Each overlay cell is a string like <code>"Amplification"</code>, <code>"Missense"</code>, or <code>""</code> for none.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(canvasXpress)</span>
<span id="cb1-2"></span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set.seed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>)</span>
<span id="cb1-4">genes   <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"TP53"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"KRAS"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PIK3CA"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PTEN"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"EGFR"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BRAF"</span>,</span>
<span id="cb1-5">             <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"APC"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"RB1"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"NF1"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MYC"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CDKN2A"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ARID1A"</span>)</span>
<span id="cb1-6">samples <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sprintf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"T%02d"</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">28</span>)</span>
<span id="cb1-7">mutrate <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">setNames</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pmax</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.05</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq_along</span>(genes) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(genes))), genes)</span>
<span id="cb1-8"></span>
<span id="cb1-9">base <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matrix</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rnorm</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(genes) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(samples)), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>),</span>
<span id="cb1-10">               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nrow =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(genes), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dimnames =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(genes, samples))</span>
<span id="cb1-11"></span>
<span id="cb1-12">CNA <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Amplification"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Deletion"</span>); MUT <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Missense"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Nonsense"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Truncating"</span>)</span>
<span id="cb1-13">cna <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mut <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matrix</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(genes), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(samples), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dimnames =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(genes, samples))</span>
<span id="cb1-14"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (g <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> genes) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (s <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> samples) {</span>
<span id="cb1-15">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">runif</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> mutrate[g])       mut[g, s] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>(MUT, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb1-16">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">runif</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> mutrate[g] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>) cna[g, s] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>(CNA, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb1-17">}</span>
<span id="cb1-18"></span>
<span id="cb1-19">smpAnnot <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Subtype =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Basal"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Luminal"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"HER2"</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(samples), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">replace =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb1-20">                      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">row.names =</span> samples)</span>
<span id="cb1-21">varAnnot <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Pathway =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"TSG"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Oncogene"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length.out =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(genes)),</span>
<span id="cb1-22">                      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">row.names =</span> genes)</span></code></pre></div>
</div>
</section>
<section id="the-plot" class="level2">
<h2 class="anchored" data-anchor-id="the-plot">The plot</h2>
<p>Pass the overlays in a named <code>data</code> list and point <code>oncoprintCNA</code> / <code>oncoprintMUT</code> at them. <code>xAxis</code> lists the samples.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">canvasXpress</span>(</span>
<span id="cb2-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data          =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> base, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data2 =</span> cna, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data3 =</span> mut),</span>
<span id="cb2-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">smpAnnot      =</span> smpAnnot, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">varAnnot =</span> varAnnot,</span>
<span id="cb2-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">graphType     =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Heatmap"</span>,</span>
<span id="cb2-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">oncoprintCNA  =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data2"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">oncoprintMUT =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data3"</span>,</span>
<span id="cb2-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">overlaysThickness =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>,</span>
<span id="cb2-7">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xAxis         =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.list</span>(samples),</span>
<span id="cb2-8">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title         =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Mutation landscape: 12 genes across 28 tumours"</span>,</span>
<span id="cb2-9">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width         =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">820</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">height =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">440</span></span>
<span id="cb2-10">)</span></code></pre></div>
<div class="cell-output-display">
<div id="htmlwidget-f507e1075fa7679317df" style="width:100%;height:348px;" class="canvasXpress html-widget"></div>
<script type="application/json" data-for="htmlwidget-f507e1075fa7679317df">{"x":{"data":{"y":{"data2":[["","","","","","Amplification","","","","","","","","Amplification","Deletion","","Amplification","","","","","","","Amplification","","","",""],["","Amplification","","","","Deletion","","","","","Deletion","","","","","Amplification","Amplification","","Deletion","Deletion","","Amplification","","","","","","Deletion"],["","Deletion","Deletion","","","Amplification","","Deletion","Amplification","Deletion","","","","","","","Amplification","","Deletion","","","","","","","","",""],["","Deletion","","Deletion","","","","Deletion","","","","","","","","","Deletion","","","","","","","","","","",""],["Amplification","","Deletion","","","","Amplification","","","","","","Amplification","Amplification","","","","","","","","","","","","","",""],["","","","","","","","","","","","","","","","","","Deletion","","","Amplification","","","","","","",""],["","","","","","Deletion","","","","","","","","","","","","","","","Deletion","","","","","","",""],["","","","","","","","","","","","","","","","","","","","","Deletion","","","","","","",""],["","","","","Amplification","","","Amplification","","","","","","","","Amplification","","","","","","","","","","","",""],["","","","","","","","","","","","","Deletion","","Deletion","","","","","","","","","","","","",""],["","","","","","","","","","","","","","","","","","","","Deletion","","","","","","","",""],["","","","","","","","","","","","","","","","","","","","","","","","","","","",""]],"data3":[["Missense","","Missense","Missense","Truncating","","Nonsense","Missense","","","Missense","Missense","","Nonsense","Nonsense","","Missense","Truncating","","Missense","","Truncating","","","","Nonsense","Missense","Truncating"],["","","","Nonsense","","Truncating","Nonsense","Truncating","","","Nonsense","","Missense","Missense","","Missense","","Missense","","","","Nonsense","","","","Missense","",""],["","","","","","","","Missense","","","Nonsense","","","","","","Missense","","","","","","","","Nonsense","Nonsense","","Missense"],["Nonsense","","","Truncating","","Truncating","","Truncating","Nonsense","","","Truncating","","","Nonsense","","","","Missense","","Nonsense","Missense","Missense","","Truncating","Truncating","Truncating",""],["","","","","","","Nonsense","","","","Missense","","","","Missense","","","Nonsense","Truncating","Truncating","","","Nonsense","","","Missense","",""],["","Missense","Truncating","","","","","Missense","","","","","Nonsense","","","Missense","Truncating","","","Truncating","Missense","","","Truncating","","","",""],["","Truncating","","","","","Missense","","Missense","Nonsense","","","Truncating","","","","","","","","","","","","","Nonsense","",""],["","","","","Truncating","","","","","","Missense","","Missense","","","","","","","","Missense","Nonsense","","","Missense","","Missense",""],["","","","","","","","","Nonsense","","","","","","","","","","","Nonsense","","","Missense","","","","","Missense"],["","","","","","","Truncating","","","","","","Missense","","","","","","","","","Missense","","","Missense","Nonsense","",""],["","","","","","","","","","","","","Truncating","Truncating","","","","","","","","","","","","","",""],["","","","","","","","","","","","Missense","","","","","","","","","","","Missense","","","","",""]],"smps":["T01","T02","T03","T04","T05","T06","T07","T08","T09","T10","T11","T12","T13","T14","T15","T16","T17","T18","T19","T20","T21","T22","T23","T24","T25","T26","T27","T28"],"vars":["TP53","KRAS","PIK3CA","PTEN","EGFR","BRAF","APC","RB1","NF1","MYC","CDKN2A","ARID1A"],"data":[[-0.84,-1.08,0.82,-1.01,-0.72,-1.14,0.35,0.68,-0.35,-0.75,1.17,-1.24,-0.31,-0.34,-0.02,2.18,-0.51,0.28,-0.14,-0.88,0.3,0.16,0.07,-1.34,1.85,1.21,0.77,-0.94],[1.38,-0.16,-0.29,-2,-0.07,0.85,0.03,-0.71,-0.54,1.28,0.88,-0.1,-0.42,1.2,-0.49,-0.68,0.45,0.41,1.42,-3.5,-0.12,-0.39,2.2,0.15,-0.69,0.19,-1.09,-1.11],[-1.26,-1.07,1.42,-1.76,1.46,-0.58,0.41,2.39,-0.18,-0.95,-1.32,0.73,0.1,-0.44,-1.44,0.75,-0.19,0.61,0.49,-0.38,-0.06,-1.84,0.8,0.29,-0.22,1.96,0.07,0.63],[0.07,-0.14,1.5,-0.14,0.19,0.5,-0.16,-0.47,-0.06,1.62,-1.64,0.46,-0.23,0.19,0.14,0.97,1.34,0.94,0.6,0.98,1.47,-1.54,-0.54,-0.12,0.68,0.14,1.61,-0.23],[1.71,-0.6,-0.66,1.55,1.02,-0.76,0.97,-0.08,-2,2.6,1.06,0.29,-1.42,-2.62,-1.23,-1.26,0.82,-0.37,0.21,-0.56,-1.48,-0.59,-1.6,0.13,0.52,-1.58,1.23,-1.37],[-0.6,-2.18,-0.85,-0.8,-0.59,-0.34,0.12,-0.52,1.14,0.14,0.29,-1.07,-0.39,2.25,-1.75,-0.28,0.08,0.74,-0.03,-0.63,-0.68,-0.85,-0.73,-0.77,0.08,-0.8,-0.38,-0.75],[-0.47,0.24,0.32,-0.07,-0.11,-2.1,0.19,0.93,0.68,-1.35,-0.4,0.65,0.95,0.09,-0.04,-0.19,-0.65,1.22,2.03,-0.53,0.46,0.78,-0.36,-1.01,0.05,1.22,-1.35,-1.13],[-0.64,-0.26,1.11,1.9,-0.92,-0.3,-0.56,-1.06,0.21,0.8,1.24,0.3,0.75,1.63,0.33,-0.38,0.73,0.63,-0.37,1.9,-0.18,-0.03,-0.99,0.97,-0.74,-0.37,0.36,-0.22],[-0.29,0.9,2.22,-0.46,0.75,-1.27,0.5,0.56,-0.06,-1.55,-1.37,-0.8,-0.52,-0.51,1.57,0.74,-0.11,0.53,-1.58,1.4,-1.16,-1.46,-0.73,-0.42,0.97,-0.16,-0.36,-0.13],[0.14,0.94,1.22,0.56,-0.11,-0.28,-1.74,0.9,0.89,0.46,-1.44,-0.03,0.81,-0.66,-1.07,-1.17,-0.3,-0.47,-0.12,-0.75,0.41,0.09,1.47,-0.83,0.98,0.56,1.37,-0.82],[1.23,1.47,1.48,-0.89,-0.06,-0.2,0.98,0.99,-0.23,0.05,1.35,2.18,-0.61,-0.04,0.92,0.67,0.99,0.82,-1.8,-0.31,-0.26,0.98,1.86,1.4,0.19,-0.86,0.29,0.47],[-0.8,0.71,0.95,-0.46,0.23,-0.23,-0.02,0.38,-1.97,-0.2,-1.98,0.96,1.24,-0.12,-0.59,0.37,-0.78,-0.43,-0.48,1.17,-0.27,-0.6,0,0.02,0.27,1.24,0.71,-0.87]]},"x":{"Subtype":["Luminal","Basal","Luminal","HER2","Basal","HER2","Basal","Basal","HER2","Basal","Luminal","Basal","Luminal","Basal","Basal","Basal","HER2","HER2","Basal","Basal","Luminal","HER2","HER2","HER2","Luminal","Luminal","HER2","Basal"]},"z":{"Pathway":["TSG","Oncogene","TSG","Oncogene","TSG","Oncogene","TSG","Oncogene","TSG","Oncogene","TSG","Oncogene"]}},"config":{"graphType":"Heatmap","isR":true,"oncoprintCNA":"data2","oncoprintMUT":"data3","overlaysThickness":100,"xAxis":["T01","T02","T03","T04","T05","T06","T07","T08","T09","T10","T11","T12","T13","T14","T15","T16","T17","T18","T19","T20","T21","T22","T23","T24","T25","T26","T27","T28"],"title":"Mutation landscape: 12 genes across 28 tumours"},"events":null,"afterRender":null},"evals":[],"jsHooks":[]}</script>
</div>
</div>
<p>canvasXpress sorts the waterfall for you and shows the alteration frequency per row. Hover a cell to read the exact alteration; swap the overlays for your own MAF / CNA calls.</p>
</section>
<section id="why-reproducible" class="level2">
<h2 class="anchored" data-anchor-id="why-reproducible">Why “reproducible”</h2>
<p>The base matrix, the overlays and the <code>config</code> <strong>are</strong> the figure — one portable spec. The same spec renders the identical oncoprint from Python or JavaScript, and can be validated and re-rendered later.</p>
</section>
<section id="next" class="level2">
<h2 class="anchored" data-anchor-id="next">Next</h2>
<ul>
<li><a href="../clustered-heatmap-in-r/">A clustered heatmap in R</a></li>
<li>Gallery: <a href="https://canvasxpress.org/examples.html" class="uri">https://canvasxpress.org/examples.html</a></li>
<li>Package: <a href="https://github.com/neuhausi/canvasXpress" class="uri">https://github.com/neuhausi/canvasXpress</a></li>
</ul>


</section>

 ]]></description>
  <category>R</category>
  <category>canvasXpress</category>
  <category>oncoprint</category>
  <category>bioinformatics</category>
  <category>visualization</category>
  <guid>https://neuhausi.github.io/canvasxpress-blog/posts/r/oncoprint-in-r/</guid>
  <pubDate>Mon, 26 Oct 2026 04:00:00 GMT</pubDate>
  <media:content url="https://neuhausi.github.io/canvasxpress-blog/posts/r/oncoprint-in-r/thumbnail.png" medium="image" type="image/png" height="73" width="144"/>
</item>
<item>
  <title>Circular (Circos-style) multi-track plots in R with canvasXpress</title>
  <dc:creator>Isaac Neuhaus</dc:creator>
  <link>https://neuhausi.github.io/canvasxpress-blog/posts/r/circos-plots-in-r/</link>
  <description><![CDATA[ 




<p>A circular (Circos-style) plot wraps a genome — or any ordered set of segments — into a ring, stacks several <strong>data tracks</strong> around it, and draws <strong>ribbons</strong> for relationships between positions. In R the reference is <code>circlize</code>. Here we build an interactive one with <a href="https://canvasxpress.org">canvasXpress</a>, from a single portable spec.</p>
<section id="the-data-shape" class="level2">
<h2 class="anchored" data-anchor-id="the-data-shape">The data shape</h2>
<p>The matrix is <strong>tracks × segments</strong> (rows are the tracks you draw, columns are the positions around the ring). A sample annotation segments the ring (here into chromosomes), and <code>circularConnections</code> is a list of <code>[colour, from, to]</code> ribbons.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(canvasXpress)</span>
<span id="cb1-2"></span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set.seed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>)</span>
<span id="cb1-4">segments <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"s"</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">80</span>)</span>
<span id="cb1-5">tracks   <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Expression"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Methylation"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CopyNumber"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Density"</span>)</span>
<span id="cb1-6">y <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matrix</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rnorm</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(tracks) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(segments)), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>),</span>
<span id="cb1-7">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nrow =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(tracks), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dimnames =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(tracks, segments))</span>
<span id="cb1-8"></span>
<span id="cb1-9">smpAnnot <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Region =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"chr"</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">each =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">row.names =</span> segments)</span>
<span id="cb1-10"></span>
<span id="cb1-11">cols  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rgb(220,40,40)"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rgb(40,120,220)"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rgb(40,160,60)"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rgb(240,150,20)"</span>)</span>
<span id="cb1-12">conns <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">18</span>, <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(i)</span>
<span id="cb1-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>(cols, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>(segments, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>(segments, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)))</span></code></pre></div>
</div>
</section>
<section id="the-plot" class="level2">
<h2 class="anchored" data-anchor-id="the-plot">The plot</h2>
<p><code>circularTrackGraphType</code> picks a renderer per track (<code>bar</code>, <code>heatmap</code>, <code>line</code>, <code>dot</code>), <code>circularTrackGraphWeight</code> sets each track’s radial thickness, and <code>segregateSamplesBy</code> splits the ring by the annotation.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">canvasXpress</span>(</span>
<span id="cb2-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data      =</span> y, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">smpAnnot =</span> smpAnnot,</span>
<span id="cb2-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">graphType =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Circular"</span>,</span>
<span id="cb2-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">circularConnections     =</span> conns,</span>
<span id="cb2-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">circularTrackGraphType  =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bar"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"heatmap"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"line"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dot"</span>),</span>
<span id="cb2-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">circularTrackGraphWeight =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span>),</span>
<span id="cb2-7">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">circularTrackName        =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>),</span>
<span id="cb2-8">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">segregateSamplesBy       =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Region"</span>),</span>
<span id="cb2-9">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title     =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Circos-style multi-track plot with connections"</span>,</span>
<span id="cb2-10">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width     =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">560</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">height =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">560</span></span>
<span id="cb2-11">)</span></code></pre></div>
<div class="cell-output-display">
<div id="htmlwidget-edcd429b618c657e7983" style="width:100%;height:650px;" class="canvasXpress html-widget"></div>
<script type="application/json" data-for="htmlwidget-edcd429b618c657e7983">{"x":{"data":{"y":{"vars":["Expression","Methylation","CopyNumber","Density"],"smps":["s1","s2","s3","s4","s5","s6","s7","s8","s9","s10","s11","s12","s13","s14","s15","s16","s17","s18","s19","s20","s21","s22","s23","s24","s25","s26","s27","s28","s29","s30","s31","s32","s33","s34","s35","s36","s37","s38","s39","s40","s41","s42","s43","s44","s45","s46","s47","s48","s49","s50","s51","s52","s53","s54","s55","s56","s57","s58","s59","s60","s61","s62","s63","s64","s65","s66","s67","s68","s69","s70","s71","s72","s73","s74","s75","s76","s77","s78","s79","s80"],"data":[[-0.08,0.74,-3.01,0.42,1.51,1.28,1.74,0.6,-1.55,0.84,0.36,0.61,0.27,0.59,-0.78,0.56,-0.27,0.4,0.78,-2.9,0.24,-1.68,0.6,-0.5,0.33,0.3,0.03,0.17,0.55,0.26,-1.14,0.48,-1.36,-1.5,0.44,1.34,0.08,-1.03,0.23,0.72,0.32,1.56,-0.38,-0.36,0.77,-1.25,2.19,-0.2,-0.9,0.56,-0.58,-0.02,0.77,0.35,-0.36,-0.87,-0.42,0.17,-0.31,-0.38,-1.04,-0.64,-0.04,-1.34,0.64,-0.35,1.32,-0.53,0.94,-1.66,-2.52,-1.07,0,0.93,0.3,-0.94,-1.47,0.29,0.78,-2.3],[0.84,-0.11,-0.59,-1.29,-0.27,-0.01,-1.11,-2.02,-0.77,-0.7,-0.61,-1.96,-0.64,-0.1,-0.6,0.09,-1.08,-1.6,-0.48,0.58,-0.79,1.22,-3.01,-0.62,-0.04,-1.9,-0.49,0.57,-1.09,1.44,-1.72,0.14,0.84,-1.35,0.5,2.44,-0.7,-0.42,0.26,-0.69,0.58,0.2,0.74,0.99,0.94,-0.38,0.08,-1.04,-0.8,-1.33,-0.22,0.89,-0.98,-0.73,0.16,-1.3,-0.04,1.48,-0.18,-0.61,0.02,0.91,0.28,-0.16,-0.85,0.41,0.42,-1.38,-0.66,-0.24,0.56,0.19,0.51,0.87,-0.5,-1.32,0.3,1.31,-1.08,-0.4],[-0.46,-0.17,-0.76,0.07,1.56,-0.4,-1.06,1.51,1.26,-0.06,0.23,-0.66,1.08,0.97,-1.5,-1.78,-0.49,-1.47,0.09,2.38,-1.09,-0.1,0.77,-1.35,-0.64,-1.65,0.61,-0.16,1.45,-1.19,-0.37,-1.73,2.23,-2.4,1.43,0.68,0.6,0.16,-0.34,0.66,-1.41,-0.39,-1.18,-0.27,-1.05,0.21,2.11,-0.13,1.32,-1.92,1.2,-0.03,0.53,0.71,-1.39,0.89,0.14,-1.55,0.84,-0.85,0.86,-0.58,1.03,-0.25,-0.72,-0.54,-0.74,-0.41,0.46,-0.73,-0.37,-0.7,-0.23,-1.62,0.17,-0.84,0.48,-0.3,0.59,1.13],[-0.55,-1.09,0.29,-0.81,-0.24,0.02,1.95,0.96,0.43,0.47,-0.26,0.28,-0.37,0.58,0.75,-1.11,1.64,1.04,0.6,-0.65,2.04,-0.95,1.57,0.77,-0.07,-1.78,-0.36,-0.84,1.39,-0.3,1.82,0.28,0.17,0.79,-1.83,-1.97,0.8,-0.56,0.3,1.73,-1,0.92,0.28,0.48,1.01,-0.12,1.03,-0.58,1.04,0.02,-1.36,-0.88,0.93,-0.32,1.37,-0.88,0.1,1.37,-0.7,1.45,0.71,0.08,-0.44,0.66,-0.14,-2.23,0.25,1.07,-0.83,0.29,-0.25,-0.05,-0.5,-0.41,-1.48,-0.18,0.07,-0.06,0.33,1.06]]},"x":{"Region":["chr1","chr1","chr1","chr1","chr1","chr1","chr1","chr1","chr1","chr1","chr1","chr1","chr1","chr1","chr1","chr1","chr1","chr1","chr1","chr1","chr2","chr2","chr2","chr2","chr2","chr2","chr2","chr2","chr2","chr2","chr2","chr2","chr2","chr2","chr2","chr2","chr2","chr2","chr2","chr2","chr3","chr3","chr3","chr3","chr3","chr3","chr3","chr3","chr3","chr3","chr3","chr3","chr3","chr3","chr3","chr3","chr3","chr3","chr3","chr3","chr4","chr4","chr4","chr4","chr4","chr4","chr4","chr4","chr4","chr4","chr4","chr4","chr4","chr4","chr4","chr4","chr4","chr4","chr4","chr4"]},"z":null},"config":{"graphType":"Circular","isR":true,"circularConnections":[["rgb(40,160,60)","s34","s37"],["rgb(220,40,40)","s75","s72"],["rgb(220,40,40)","s24","s1"],["rgb(220,40,40)","s12","s15"],["rgb(40,160,60)","s22","s44"],["rgb(220,40,40)","s36","s78"],["rgb(220,40,40)","s70","s39"],["rgb(220,40,40)","s65","s78"],["rgb(40,120,220)","s9","s55"],["rgb(240,150,20)","s31","s28"],["rgb(40,120,220)","s22","s64"],["rgb(40,120,220)","s35","s1"],["rgb(40,160,60)","s17","s65"],["rgb(240,150,20)","s11","s23"],["rgb(40,160,60)","s34","s21"],["rgb(220,40,40)","s8","s29"],["rgb(240,150,20)","s65","s64"],["rgb(220,40,40)","s29","s79"]],"circularTrackGraphType":["bar","heatmap","line","dot"],"circularTrackGraphWeight":[30,20,25,25],"circularTrackName":[1,2,3,4],"segregateSamplesBy":["Region"],"title":"Circos-style multi-track plot with connections"},"events":null,"afterRender":null},"evals":[],"jsHooks":[]}</script>
</div>
</div>
<p>Each ring is one track; the inner ribbons are the connections. Hover a segment to read its values; swap the matrix and ribbons for your own genomic tracks and interactions.</p>
</section>
<section id="why-reproducible" class="level2">
<h2 class="anchored" data-anchor-id="why-reproducible">Why “reproducible”</h2>
<p>The matrix, the connections and the <code>config</code> <strong>are</strong> the figure — one portable spec. The same spec renders the identical circular plot from Python or JavaScript, and can be validated and re-rendered later.</p>
</section>
<section id="next" class="level2">
<h2 class="anchored" data-anchor-id="next">Next</h2>
<ul>
<li><a href="../genome-tracks-in-r/">Genome browser tracks in R</a></li>
<li>Gallery: <a href="https://canvasxpress.org/examples.html" class="uri">https://canvasxpress.org/examples.html</a></li>
<li>Package: <a href="https://github.com/neuhausi/canvasXpress" class="uri">https://github.com/neuhausi/canvasXpress</a></li>
</ul>


</section>

 ]]></description>
  <category>R</category>
  <category>canvasXpress</category>
  <category>circos</category>
  <category>bioinformatics</category>
  <category>visualization</category>
  <guid>https://neuhausi.github.io/canvasxpress-blog/posts/r/circos-plots-in-r/</guid>
  <pubDate>Fri, 23 Oct 2026 04:00:00 GMT</pubDate>
  <media:content url="https://neuhausi.github.io/canvasxpress-blog/posts/r/circos-plots-in-r/thumbnail.png" medium="image" type="image/png" height="139" width="144"/>
</item>
<item>
  <title>Choropleth maps in R with canvasXpress</title>
  <dc:creator>Isaac Neuhaus</dc:creator>
  <link>https://neuhausi.github.io/canvasxpress-blog/posts/r/choropleth-maps-in-r/</link>
  <description><![CDATA[ 




<p>A choropleth shades each region by a value — emissions, incidence, turnout, income. It is the most common map in data analysis and the easiest to get <em>subtly wrong</em>: most “my map is all one colour” complaints are not rendering bugs but scale bugs. This post builds a choropleth in R with <a href="https://canvasxpress.org">canvasXpress</a> that stays vivid and honest on exactly the kind of heavy-tailed data that flattens naive maps. The join and the colouring happen inside the render, so every figure is one portable spec you can re-run from R, Python or the browser.</p>
<section id="first-the-trap-colour-encodes-a-rate-not-a-count" class="level2">
<h2 class="anchored" data-anchor-id="first-the-trap-colour-encodes-a-rate-not-a-count">First, the trap: colour encodes a <em>rate</em>, not a <em>count</em></h2>
<p>A choropleth fills an <strong>area</strong>, and area is a size channel your eye cannot help reading. Shade countries by a raw count — total cases, total emissions, total sales — and big, populous regions light up simply because they are big and populous. You have drawn a population map with extra steps.</p>
<p>The fix is almost always to map a <strong>rate or density</strong>: cases per 100k, emissions per capita, sales per store. Reserve raw counts for a <em>proportional-symbol</em> map (a sized bubble at each centroid), where the size channel carries the count honestly. Decide which question you are answering before you pick the geometry — this one choice prevents most misleading maps.</p>
</section>
<section id="one-value-per-region" class="level2">
<h2 class="anchored" data-anchor-id="one-value-per-region">One value per region</h2>
<p>A choropleth needs exactly one measurement per shape. In canvasXpress the <strong>columns</strong> are the regions (they match the map by name) and the <strong>row</strong> is the variable you colour by — here CO₂ emissions per country for 2018. Load a prepared table; swap it for your own (any <code>country → value</code> table works).</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(canvasXpress)</span>
<span id="cb1-2"></span>
<span id="cb1-3">y <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read.table</span>(</span>
<span id="cb1-4">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://www.canvasxpress.org/data/r/cX-CO2-dat.txt"</span>,</span>
<span id="cb1-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">header =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sep =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\t</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">quote =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">row.names =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,</span>
<span id="cb1-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">check.names =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stringsAsFactors =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span></span>
<span id="cb1-7">)</span>
<span id="cb1-8"></span>
<span id="cb1-9"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dim</span>(y)              <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 1 row (CO2) x N countries</span></span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1]   1 198</code></pre>
</div>
<div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1">y[, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>]</span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>    Afghanistan  Albania  Algeria Andorra
CO2    10.45267 5.402999 164.3093 0.46421</code></pre>
</div>
</div>
<p>The single row is the variable (<code>CO2</code>); each column name is a country that must match a shape in the map. An optional <strong>sample annotation</strong> table (rows = countries) rides along for richer tooltips and legends — here the continent and ISO code.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1">x <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read.table</span>(</span>
<span id="cb5-2">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://www.canvasxpress.org/data/r/cX-CO2-smp.txt"</span>,</span>
<span id="cb5-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">header =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sep =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\t</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">quote =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">row.names =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,</span>
<span id="cb5-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">check.names =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stringsAsFactors =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span></span>
<span id="cb5-5">)</span>
<span id="cb5-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(x)</span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>            Code     Continent     Country
Afghanistan  AFG          Asia Afghanistan
Albania      ALB        Europe     Albania
Algeria      DZA        Africa     Algeria
Andorra      AND        Europe     Andorra
Angola       AGO        Africa      Angola
Anguilla     AIA North America    Anguilla</code></pre>
</div>
</div>
</section>
<section id="the-map-quantile-classes-computed-in-r-painted-by-the-map" class="level2">
<h2 class="anchored" data-anchor-id="the-map-quantile-classes-computed-in-r-painted-by-the-map">The map: quantile classes computed in R, painted by the map</h2>
<p><code>graphType = "Map"</code> with a <code>topoJSON</code> of world boundaries draws the shapes and joins the countries by name — no manual merge, no projection math. The statistics stay in R, where they belong: we cut the values into <strong>seven quantile classes</strong> with <code>quantile()</code> + <code>cut()</code>, so each class holds an equal number of countries (~28 of 198), then colour by that classed annotation with a viridis palette. On skewed data that equal-count guarantee is what keeps all seven colours on the map.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1">vals   <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>(y[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, ])</span>
<span id="cb7-2">breaks <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(vals, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">probs =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length.out =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>)))</span>
<span id="cb7-3">cls    <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cut</span>(vals, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> breaks, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">include.lowest =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb7-4">x<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Emissions <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sprintf</span>(</span>
<span id="cb7-5">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Q%d: %s"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.integer</span>(cls),</span>
<span id="cb7-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">","</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" - "</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"[][()]"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">levels</span>(cls)))[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.integer</span>(cls)]</span>
<span id="cb7-7">)</span>
<span id="cb7-8"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">table</span>(x<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Emissions)   <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># ~28 countries per class</span></span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>
Q1: 0.00765 - 0.564    Q2: 0.564 - 2.69      Q3: 2.69 - 7.8      Q4: 7.8 - 22.4 
                 29                  28                  28                  28 
      Q5: 22.4 - 46        Q6: 46 - 208  Q7: 208 - 9.96e+03 
                 28                  28                  29 </code></pre>
</div>
</div>
<div class="cell">
<div class="sourceCode cell-code" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">canvasXpress</span>(</span>
<span id="cb9-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data      =</span> y,</span>
<span id="cb9-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">smpAnnot  =</span> x,</span>
<span id="cb9-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">graphType =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Map"</span>,</span>
<span id="cb9-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colorBy   =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Emissions"</span>,</span>
<span id="cb9-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">topoJSON  =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://www.canvasxpress.org/data/maps/WORLD.json"</span>,</span>
<span id="cb9-7">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mapId     =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"co2Quantile"</span>,</span>
<span id="cb9-8">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colors =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#440154"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#443983"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#31688e"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#21918c"</span>,</span>
<span id="cb9-9">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#35b779"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#90d743"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#fde725"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#d9dde3"</span>),</span>
<span id="cb9-10">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mapColor        =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#d9dde3"</span>,</span>
<span id="cb9-11">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mapOutlineColor =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#ffffff"</span>,</span>
<span id="cb9-12">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legendPosition  =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bottom"</span>,</span>
<span id="cb9-13">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legendColumns   =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>,</span>
<span id="cb9-14">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title    =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CO2 emissions per country (2018)"</span>,</span>
<span id="cb9-15">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Seven quantile classes computed in R: each colour holds about 28 of 198 countries"</span>,</span>
<span id="cb9-16">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width  =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">760</span>,</span>
<span id="cb9-17">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">height =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">560</span></span>
<span id="cb9-18">)</span></code></pre></div>
<div class="cell-output-display">
<div id="htmlwidget-f5120841cd0cc6fc003d" style="width:100%;height:478px;" class="canvasXpress html-widget"></div>
<script type="application/json" data-for="htmlwidget-f5120841cd0cc6fc003d">{"x":{"data":{"y":{"vars":["CO2"],"smps":["Afghanistan","Albania","Algeria","Andorra","Angola","Anguilla","Antigua & Barbuda","Argentina","Armenia","Aruba","Australia","Austria","Azerbaijan","Bahamas","Bahrain","Bangladesh","Barbados","Belarus","Belgium","Belize","Benin","Bermuda","Bhutan","Bolivia","Bosnia and Herzegovina","Botswana","Brazil","British Virgin Islands","Brunei Darussalam","Bulgaria","Burkina Faso","Burundi","Cambodia","Cameroon","Canada","Cape Verde","Central African Republic","Chad","Chile","China","Colombia","Comoros","Congo","Cook Islands","Costa Rica","Croatia","Cuba","Cyprus","Czechia","Democratic Republic of the Congo","Denmark","Djibouti","Dominican Republic","Ecuador","Egypt","El Salvador","Equatorial Guinea","Eritrea","Estonia","Ethiopia","Fiji","Finland","France","French Polynesia","Gabon","Gambia","Georgia","Germany","Ghana","Greece","Greenland","Grenada","Guatemala","Guinea","Guinea-Bissau","Guyana","Haiti","Honduras","Hong Kong","Hungary","Iceland","India","Indonesia","Iran","Iraq","Ireland","Israel","Italy","Jamaica","Japan","Jordan","Kazakhstan","Kenya","Kiribati","Kuwait","Kyrgyzstan","Lao People's Democratic Republic","Latvia","Lebanon","Lesotho","Liberia","Libya","Liechtenstein","Lithuania","Luxembourg","Macao","Madagascar","Malawi","Malaysia","Maldives","Mali","Malta","Marshall Islands","Mauritania","Mauritius","Mexico","Moldova","Mongolia","Montenegro","Morocco","Mozambique","Myanmar","Namibia","Nauru","Nepal","Netherlands","New Caledonia","New Zealand","Nicaragua","Niger","Nigeria","Niue","Democratic People's Republic of Korea","The former Yugoslav Republic of Macedonia","Norway","Oman","Pakistan","Panama","Papua New Guinea","Paraguay","Peru","Philippines","Poland","Portugal","Qatar","Romania","Russia","Rwanda","Saint Helena","Saint Kitts and Nevis","Saint Lucia","Saint Pierre and Miquelon","Saint Vincent and the Grenadines","Samoa","Sao Tome and Principe","Saudi Arabia","Serbia","Seychelles","Sierra Leone","Singapore","Slovakia","Slovenia","Solomon Islands","Somalia","Republic of Korea","South Sudan","Spain","Sri Lanka","Sudan","Suriname","Sweden","Switzerland","Syria","Taiwan","Tajikistan","Tanzania","Thailand","Timor-Leste","Togo","Tonga","Trinidad and Tobago","Tunisia","Turkey","Turkmenistan","Tuvalu","Uganda","Ukraine","United Arab Emirates","United Kingdom","United States","Uruguay","Uzbekistan","Vanuatu","Venezuela","Vietnam","Yemen","Zambia","Zimbabwe"],"data":[[10.45,5.403,164.3,0.4642,37.68,0.1471,0.5056,185,6.297,0.9432,416,66.72,37.49,2.03,31.59,85.72,1.207,61.87,100.2,0.6122,7.76,0.6489,1.662,22.35,22.09,6.815,466.6,0.1736,9.56,43.55,4.14,0.568,15.48,7.567,586.5,0.6095,0.3005,1.008,85.83,9957,92.23,0.2459,3.518,0.07271,8.249,17.72,26.08,7.333,104.4,2.231,34.65,0.39,25.31,41.82,251.5,6.018,5.906,0.7088,17.71,16.18,2.124,45.85,331.7,0.7806,4.803,0.5632,9.862,755.4,14.48,71.8,0.5117,0.2786,19.41,3.032,0.3086,2.343,3.367,10.47,42.51,49.63,3.675,2591,576.6,755.4,211.3,38.8,62.21,348.1,8.01,1136,24.92,319.6,17.14,0.06888,104.2,10.17,32.26,7.859,27.57,2.426,1.274,45.21,0.1437,13.67,9.569,2.216,4.188,1.47,249.1,1.565,3.273,1.532,0.1531,3.935,4.902,451.1,5.878,64.51,2.123,65.37,8.383,26.1,4.154,0.04975,13.41,160.2,8.209,35.08,5.377,2.094,136.1,0.007653,38.16,6.981,43.82,71.03,247.4,12.1,6.786,8.103,54.21,138.9,337.7,51.48,109.2,76.95,1691,1.08,0.01132,0.249,0.3622,0.07923,0.2641,0.2679,0.1261,576.8,46.05,0.6054,0.9876,38.29,36.09,14.49,0.2985,0.6583,634.9,1.54,269.7,22.97,22.37,2.552,41.77,36.9,25.88,273.1,7.473,11.5,292.5,0.5204,3.167,0.1645,37.87,30.36,419.2,78.03,0.01148,5.385,231.7,188.5,380.1,5425,6.252,113.9,0.1454,129.6,211.8,9.945,6.93,11.34]]},"x":{"Code":["AFG","ALB","DZA","AND","AGO","AIA","ATG","ARG","ARM","ABW","AUS","AUT","AZE","BHS","BHR","BGD","BRB","BLR","BEL","BLZ","BEN","BMU","BTN","BOL","BIH","BWA","BRA","VGB","BRN","BGR","BFA","BDI","KHM","CMR","CAN","CPV","CAF","TCD","CHL","CHN","COL","COM","COG","COK","CRI","HRV","CUB","CYP","CZE","COD","DNK","DJI","DOM","ECU","EGY","SLV","GNQ","ERI","EST","ETH","FJI","FIN","FRA","PYF","GAB","GMB","GEO","DEU","GHA","GRC","GRL","GRD","GTM","GIN","GNB","GUY","HTI","HND","HKG","HUN","ISL","IND","IDN","IRN","IRQ","IRL","ISR","ITA","JAM","JPN","JOR","KAZ","KEN","KIR","KWT","KGZ","LAO","LVA","LBN","LSO","LBR","LBY","LIE","LTU","LUX","MAC","MDG","MWI","MYS","MDV","MLI","MLT","MHL","MRT","MUS","MEX","MDA","MNG","MNE","MAR","MOZ","MMR","NAM","NRU","NPL","NLD","NCL","NZL","NIC","NER","NGA","NIU","PRK","MKD","NOR","OMN","PAK","PAN","PNG","PRY","PER","PHL","POL","PRT","QAT","ROU","RUS","RWA","SHN","KNA","LCA","SPM","VCT","WSM","STP","SAU","SRB","SYC","SLE","SGP","SVK","SVN","SLB","SOM","KOR","SSD","ESP","LKA","SDN","SUR","SWE","CHE","SYR","TWN","TJK","TZA","THA","TLS","TGO","TON","TTO","TUN","TUR","TKM","TUV","UGA","UKR","ARE","GBR","USA","URY","UZB","VUT","VEN","VNM","YEM","ZMB","ZWE"],"Continent":["Asia","Europe","Africa","Europe","Africa","North America","North America","South America","Asia","North America","Oceania","Europe","Europe","North America","Asia","Asia","North America","Europe","Europe","North America","Africa","North America","Asia","South America","Europe","Africa","South America","North America","Asia","Europe","Africa","Africa","Asia","Africa","North America","Africa","Africa","Africa","South America","Asia","South America","Africa","Africa","Oceania","Central America","Europe","North America","Europe","Europe","Africa","Europe","Africa","North America","South America","Africa","Central America","Africa","Africa","Europe","Africa","Oceania","Europe","Europe","Oceania","Africa","Africa","Asia","Europe","Africa","Europe","North America","North America","Central America","Africa","Africa","South America","North America","Central America","Asia","Europe","Europe","Asia","Asia","Asia","Asia","Europe","Asia","Europe","North America","Asia","Asia","Asia","Africa","Oceania","Asia","Asia","Asia","Europe","Asia","Africa","Africa","Africa","Europe","Europe","Europe","Asia","Africa","Africa","Asia","Asia","Africa","Europe","Oceania","Africa","Africa","North America","Europe","Asia","Europe","Africa","Africa","Asia","Africa","Oceania","Asia","Europe","Oceania","Oceania","Central America","Africa","Africa","Oceania","Asia","Europe","Europe","Asia","Asia","Central America","Oceania","South America","South America","Asia","Europe","Europe","Africa","Europe","Asia","Africa","Africa","North America","North America","North America","North America","Oceania","Africa","Asia","Europe","Africa","Africa","Asia","Europe","Europe","Oceania","Africa","Asia","Africa","Europe","Asia","Africa","South America","Europe","Europe","Asia","Asia","Asia","Africa","Asia","Asia","Africa","Oceania","North America","Africa","Asia","Asia","Oceania","Africa","Europe","Asia","Europe","North America","South America","Asia","Oceania","South America","Asia","Asia","Africa","Africa"],"Country":["Afghanistan","Albania","Algeria","Andorra","Angola","Anguilla","Antigua & Barbuda","Argentina","Armenia","Aruba","Australia","Austria","Azerbaijan","Bahamas","Bahrain","Bangladesh","Barbados","Belarus","Belgium","Belize","Benin","Bermuda","Bhutan","Bolivia","Bosnia and Herzegovina","Botswana","Brazil","British Virgin Islands","Brunei Darussalam","Bulgaria","Burkina Faso","Burundi","Cambodia","Cameroon","Canada","Cape Verde","Central African Republic","Chad","Chile","China","Colombia","Comoros","Congo","Cook Islands","Costa Rica","Croatia","Cuba","Cyprus","Czechia","Democratic Republic of the Congo","Denmark","Djibouti","Dominican Republic","Ecuador","Egypt","El Salvador","Equatorial Guinea","Eritrea","Estonia","Ethiopia","Fiji","Finland","France","French Polynesia","Gabon","Gambia","Georgia","Germany","Ghana","Greece","Greenland","Grenada","Guatemala","Guinea","Guinea-Bissau","Guyana","Haiti","Honduras","Hong Kong","Hungary","Iceland","India","Indonesia","Iran","Iraq","Ireland","Israel","Italy","Jamaica","Japan","Jordan","Kazakhstan","Kenya","Kiribati","Kuwait","Kyrgyzstan","Lao People's Democratic Republic","Latvia","Lebanon","Lesotho","Liberia","Libya","Liechtenstein","Lithuania","Luxembourg","Macao","Madagascar","Malawi","Malaysia","Maldives","Mali","Malta","Marshall Islands","Mauritania","Mauritius","Mexico","Moldova","Mongolia","Montenegro","Morocco","Mozambique","Myanmar","Namibia","Nauru","Nepal","Netherlands","New Caledonia","New Zealand","Nicaragua","Niger","Nigeria","Niue","Democratic People's Republic of Korea","The former Yugoslav Republic of Macedonia","Norway","Oman","Pakistan","Panama","Papua New Guinea","Paraguay","Peru","Philippines","Poland","Portugal","Qatar","Romania","Russia","Rwanda","Saint Helena","Saint Kitts and Nevis","Saint Lucia","Saint Pierre and Miquelon","Saint Vincent and the Grenadines","Samoa","Sao Tome and Principe","Saudi Arabia","Serbia","Seychelles","Sierra Leone","Singapore","Slovakia","Slovenia","Solomon Islands","Somalia","Republic of Korea","South Sudan","Spain","Sri Lanka","Sudan","Suriname","Sweden","Switzerland","Syria","Taiwan","Tajikistan","Tanzania","Thailand","Timor-Leste","Togo","Tonga","Trinidad and Tobago","Tunisia","Turkey","Turkmenistan","Tuvalu","Uganda","Ukraine","United Arab Emirates","United Kingdom","United States","Uruguay","Uzbekistan","Vanuatu","Venezuela","Vietnam","Yemen","Zambia","Zimbabwe"],"Emissions":["Q4: 7.8 - 22.4","Q3: 2.69 - 7.8","Q6: 46 - 208","Q1: 0.00765 - 0.564","Q5: 22.4 - 46","Q1: 0.00765 - 0.564","Q1: 0.00765 - 0.564","Q6: 46 - 208","Q3: 2.69 - 7.8","Q2: 0.564 - 2.69","Q7: 208 - 9.96e+03","Q6: 46 - 208","Q5: 22.4 - 46","Q2: 0.564 - 2.69","Q5: 22.4 - 46","Q6: 46 - 208","Q2: 0.564 - 2.69","Q6: 46 - 208","Q6: 46 - 208","Q2: 0.564 - 2.69","Q3: 2.69 - 7.8","Q2: 0.564 - 2.69","Q2: 0.564 - 2.69","Q4: 7.8 - 22.4","Q4: 7.8 - 22.4","Q3: 2.69 - 7.8","Q7: 208 - 9.96e+03","Q1: 0.00765 - 0.564","Q4: 7.8 - 22.4","Q5: 22.4 - 46","Q3: 2.69 - 7.8","Q2: 0.564 - 2.69","Q4: 7.8 - 22.4","Q3: 2.69 - 7.8","Q7: 208 - 9.96e+03","Q2: 0.564 - 2.69","Q1: 0.00765 - 0.564","Q2: 0.564 - 2.69","Q6: 46 - 208","Q7: 208 - 9.96e+03","Q6: 46 - 208","Q1: 0.00765 - 0.564","Q3: 2.69 - 7.8","Q1: 0.00765 - 0.564","Q4: 7.8 - 22.4","Q4: 7.8 - 22.4","Q5: 22.4 - 46","Q3: 2.69 - 7.8","Q6: 46 - 208","Q2: 0.564 - 2.69","Q5: 22.4 - 46","Q1: 0.00765 - 0.564","Q5: 22.4 - 46","Q5: 22.4 - 46","Q7: 208 - 9.96e+03","Q3: 2.69 - 7.8","Q3: 2.69 - 7.8","Q2: 0.564 - 2.69","Q4: 7.8 - 22.4","Q4: 7.8 - 22.4","Q2: 0.564 - 2.69","Q5: 22.4 - 46","Q7: 208 - 9.96e+03","Q2: 0.564 - 2.69","Q3: 2.69 - 7.8","Q1: 0.00765 - 0.564","Q4: 7.8 - 22.4","Q7: 208 - 9.96e+03","Q4: 7.8 - 22.4","Q6: 46 - 208","Q1: 0.00765 - 0.564","Q1: 0.00765 - 0.564","Q4: 7.8 - 22.4","Q3: 2.69 - 7.8","Q1: 0.00765 - 0.564","Q2: 0.564 - 2.69","Q3: 2.69 - 7.8","Q4: 7.8 - 22.4","Q5: 22.4 - 46","Q6: 46 - 208","Q3: 2.69 - 7.8","Q7: 208 - 9.96e+03","Q7: 208 - 9.96e+03","Q7: 208 - 9.96e+03","Q7: 208 - 9.96e+03","Q5: 22.4 - 46","Q6: 46 - 208","Q7: 208 - 9.96e+03","Q4: 7.8 - 22.4","Q7: 208 - 9.96e+03","Q5: 22.4 - 46","Q7: 208 - 9.96e+03","Q4: 7.8 - 22.4","Q1: 0.00765 - 0.564","Q6: 46 - 208","Q4: 7.8 - 22.4","Q5: 22.4 - 46","Q4: 7.8 - 22.4","Q5: 22.4 - 46","Q2: 0.564 - 2.69","Q2: 0.564 - 2.69","Q5: 22.4 - 46","Q1: 0.00765 - 0.564","Q4: 7.8 - 22.4","Q4: 7.8 - 22.4","Q2: 0.564 - 2.69","Q3: 2.69 - 7.8","Q2: 0.564 - 2.69","Q7: 208 - 9.96e+03","Q2: 0.564 - 2.69","Q3: 2.69 - 7.8","Q2: 0.564 - 2.69","Q1: 0.00765 - 0.564","Q3: 2.69 - 7.8","Q3: 2.69 - 7.8","Q7: 208 - 9.96e+03","Q3: 2.69 - 7.8","Q6: 46 - 208","Q2: 0.564 - 2.69","Q6: 46 - 208","Q4: 7.8 - 22.4","Q5: 22.4 - 46","Q3: 2.69 - 7.8","Q1: 0.00765 - 0.564","Q4: 7.8 - 22.4","Q6: 46 - 208","Q4: 7.8 - 22.4","Q5: 22.4 - 46","Q3: 2.69 - 7.8","Q2: 0.564 - 2.69","Q6: 46 - 208","Q1: 0.00765 - 0.564","Q5: 22.4 - 46","Q3: 2.69 - 7.8","Q5: 22.4 - 46","Q6: 46 - 208","Q7: 208 - 9.96e+03","Q4: 7.8 - 22.4","Q3: 2.69 - 7.8","Q4: 7.8 - 22.4","Q6: 46 - 208","Q6: 46 - 208","Q7: 208 - 9.96e+03","Q6: 46 - 208","Q6: 46 - 208","Q6: 46 - 208","Q7: 208 - 9.96e+03","Q2: 0.564 - 2.69","Q1: 0.00765 - 0.564","Q1: 0.00765 - 0.564","Q1: 0.00765 - 0.564","Q1: 0.00765 - 0.564","Q1: 0.00765 - 0.564","Q1: 0.00765 - 0.564","Q1: 0.00765 - 0.564","Q7: 208 - 9.96e+03","Q6: 46 - 208","Q2: 0.564 - 2.69","Q2: 0.564 - 2.69","Q5: 22.4 - 46","Q5: 22.4 - 46","Q4: 7.8 - 22.4","Q1: 0.00765 - 0.564","Q2: 0.564 - 2.69","Q7: 208 - 9.96e+03","Q2: 0.564 - 2.69","Q7: 208 - 9.96e+03","Q5: 22.4 - 46","Q5: 22.4 - 46","Q2: 0.564 - 2.69","Q5: 22.4 - 46","Q5: 22.4 - 46","Q5: 22.4 - 46","Q7: 208 - 9.96e+03","Q3: 2.69 - 7.8","Q4: 7.8 - 22.4","Q7: 208 - 9.96e+03","Q1: 0.00765 - 0.564","Q3: 2.69 - 7.8","Q1: 0.00765 - 0.564","Q5: 22.4 - 46","Q5: 22.4 - 46","Q7: 208 - 9.96e+03","Q6: 46 - 208","Q1: 0.00765 - 0.564","Q3: 2.69 - 7.8","Q7: 208 - 9.96e+03","Q6: 46 - 208","Q7: 208 - 9.96e+03","Q7: 208 - 9.96e+03","Q3: 2.69 - 7.8","Q6: 46 - 208","Q1: 0.00765 - 0.564","Q6: 46 - 208","Q7: 208 - 9.96e+03","Q4: 7.8 - 22.4","Q3: 2.69 - 7.8","Q4: 7.8 - 22.4"]},"z":null},"config":{"graphType":"Map","isR":true,"colorBy":"Emissions","topoJSON":"https://www.canvasxpress.org/data/maps/WORLD.json","mapId":"co2Quantile","colors":["#440154","#443983","#31688e","#21918c","#35b779","#90d743","#fde725","#d9dde3"],"mapColor":"#d9dde3","mapOutlineColor":"#ffffff","legendPosition":"bottom","legendColumns":4,"title":"CO2 emissions per country (2018)","subtitle":"Seven quantile classes computed in R: each colour holds about 28 of 198 countries"},"events":null,"afterRender":null},"evals":[],"jsHooks":[]}</script>
</div>
</div>
<p>Every band of the ramp is doing work: the darkest purples are the smallest emitters, the yellows the largest, and the legend states each class’s actual value range — the edges are <em>data-driven</em>, not evenly spaced. The eighth colour, a neutral grey, catches map regions with no data so missing reads as missing. Hover any country for its name, continent, class and value.</p>
<p>If you prefer to keep the classing inside the engine, current CanvasXpress builds accept <code>colorSpectrum</code> (the ramp) plus <code>colorSpectrumBreaksMethod = "quantile"</code> and do the same cut at render time — the R route above works everywhere and keeps the breaks inspectable in your session.</p>
</section>
<section id="why-not-just-a-plain-linear-ramp" class="level2">
<h2 class="anchored" data-anchor-id="why-not-just-a-plain-linear-ramp">Why not just a plain linear ramp?</h2>
<p>Because the data is <strong>heavy-tailed</strong> — a few countries emit thousands of megatonnes while most emit almost nothing. On a linear scale, <strong>195 of these 198 countries fall into the bottom fifth of the range</strong>, so a continuous ramp paints nearly the whole world one pale tone and spends its colour on two or three outliers:</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">canvasXpress</span>(</span>
<span id="cb10-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data      =</span> y,</span>
<span id="cb10-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">smpAnnot  =</span> x,</span>
<span id="cb10-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">graphType =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Map"</span>,</span>
<span id="cb10-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colorBy   =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CO2"</span>,</span>
<span id="cb10-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">topoJSON  =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://www.canvasxpress.org/data/maps/WORLD.json"</span>,</span>
<span id="cb10-7">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mapId     =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"co2Linear"</span>,</span>
<span id="cb10-8">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legendPosition =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"left"</span>,</span>
<span id="cb10-9">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">theme =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"solarized"</span>,</span>
<span id="cb10-10">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title    =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"The same data on a plain linear ramp"</span>,</span>
<span id="cb10-11">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"195 of 198 countries sit in the bottom fifth of the scale - the map goes flat"</span>,</span>
<span id="cb10-12">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width  =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">700</span>,</span>
<span id="cb10-13">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">height =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">480</span></span>
<span id="cb10-14">)</span></code></pre></div>
<div class="cell-output-display">
<div id="htmlwidget-87196521e49fb3a0b9fd" style="width:100%;height:445px;" class="canvasXpress html-widget"></div>
<script type="application/json" data-for="htmlwidget-87196521e49fb3a0b9fd">{"x":{"data":{"y":{"vars":["CO2"],"smps":["Afghanistan","Albania","Algeria","Andorra","Angola","Anguilla","Antigua & Barbuda","Argentina","Armenia","Aruba","Australia","Austria","Azerbaijan","Bahamas","Bahrain","Bangladesh","Barbados","Belarus","Belgium","Belize","Benin","Bermuda","Bhutan","Bolivia","Bosnia and Herzegovina","Botswana","Brazil","British Virgin Islands","Brunei Darussalam","Bulgaria","Burkina Faso","Burundi","Cambodia","Cameroon","Canada","Cape Verde","Central African Republic","Chad","Chile","China","Colombia","Comoros","Congo","Cook Islands","Costa Rica","Croatia","Cuba","Cyprus","Czechia","Democratic Republic of the Congo","Denmark","Djibouti","Dominican Republic","Ecuador","Egypt","El Salvador","Equatorial Guinea","Eritrea","Estonia","Ethiopia","Fiji","Finland","France","French Polynesia","Gabon","Gambia","Georgia","Germany","Ghana","Greece","Greenland","Grenada","Guatemala","Guinea","Guinea-Bissau","Guyana","Haiti","Honduras","Hong Kong","Hungary","Iceland","India","Indonesia","Iran","Iraq","Ireland","Israel","Italy","Jamaica","Japan","Jordan","Kazakhstan","Kenya","Kiribati","Kuwait","Kyrgyzstan","Lao People's Democratic Republic","Latvia","Lebanon","Lesotho","Liberia","Libya","Liechtenstein","Lithuania","Luxembourg","Macao","Madagascar","Malawi","Malaysia","Maldives","Mali","Malta","Marshall Islands","Mauritania","Mauritius","Mexico","Moldova","Mongolia","Montenegro","Morocco","Mozambique","Myanmar","Namibia","Nauru","Nepal","Netherlands","New Caledonia","New Zealand","Nicaragua","Niger","Nigeria","Niue","Democratic People's Republic of Korea","The former Yugoslav Republic of Macedonia","Norway","Oman","Pakistan","Panama","Papua New Guinea","Paraguay","Peru","Philippines","Poland","Portugal","Qatar","Romania","Russia","Rwanda","Saint Helena","Saint Kitts and Nevis","Saint Lucia","Saint Pierre and Miquelon","Saint Vincent and the Grenadines","Samoa","Sao Tome and Principe","Saudi Arabia","Serbia","Seychelles","Sierra Leone","Singapore","Slovakia","Slovenia","Solomon Islands","Somalia","Republic of Korea","South Sudan","Spain","Sri Lanka","Sudan","Suriname","Sweden","Switzerland","Syria","Taiwan","Tajikistan","Tanzania","Thailand","Timor-Leste","Togo","Tonga","Trinidad and Tobago","Tunisia","Turkey","Turkmenistan","Tuvalu","Uganda","Ukraine","United Arab Emirates","United Kingdom","United States","Uruguay","Uzbekistan","Vanuatu","Venezuela","Vietnam","Yemen","Zambia","Zimbabwe"],"data":[[10.45,5.403,164.3,0.4642,37.68,0.1471,0.5056,185,6.297,0.9432,416,66.72,37.49,2.03,31.59,85.72,1.207,61.87,100.2,0.6122,7.76,0.6489,1.662,22.35,22.09,6.815,466.6,0.1736,9.56,43.55,4.14,0.568,15.48,7.567,586.5,0.6095,0.3005,1.008,85.83,9957,92.23,0.2459,3.518,0.07271,8.249,17.72,26.08,7.333,104.4,2.231,34.65,0.39,25.31,41.82,251.5,6.018,5.906,0.7088,17.71,16.18,2.124,45.85,331.7,0.7806,4.803,0.5632,9.862,755.4,14.48,71.8,0.5117,0.2786,19.41,3.032,0.3086,2.343,3.367,10.47,42.51,49.63,3.675,2591,576.6,755.4,211.3,38.8,62.21,348.1,8.01,1136,24.92,319.6,17.14,0.06888,104.2,10.17,32.26,7.859,27.57,2.426,1.274,45.21,0.1437,13.67,9.569,2.216,4.188,1.47,249.1,1.565,3.273,1.532,0.1531,3.935,4.902,451.1,5.878,64.51,2.123,65.37,8.383,26.1,4.154,0.04975,13.41,160.2,8.209,35.08,5.377,2.094,136.1,0.007653,38.16,6.981,43.82,71.03,247.4,12.1,6.786,8.103,54.21,138.9,337.7,51.48,109.2,76.95,1691,1.08,0.01132,0.249,0.3622,0.07923,0.2641,0.2679,0.1261,576.8,46.05,0.6054,0.9876,38.29,36.09,14.49,0.2985,0.6583,634.9,1.54,269.7,22.97,22.37,2.552,41.77,36.9,25.88,273.1,7.473,11.5,292.5,0.5204,3.167,0.1645,37.87,30.36,419.2,78.03,0.01148,5.385,231.7,188.5,380.1,5425,6.252,113.9,0.1454,129.6,211.8,9.945,6.93,11.34]]},"x":{"Code":["AFG","ALB","DZA","AND","AGO","AIA","ATG","ARG","ARM","ABW","AUS","AUT","AZE","BHS","BHR","BGD","BRB","BLR","BEL","BLZ","BEN","BMU","BTN","BOL","BIH","BWA","BRA","VGB","BRN","BGR","BFA","BDI","KHM","CMR","CAN","CPV","CAF","TCD","CHL","CHN","COL","COM","COG","COK","CRI","HRV","CUB","CYP","CZE","COD","DNK","DJI","DOM","ECU","EGY","SLV","GNQ","ERI","EST","ETH","FJI","FIN","FRA","PYF","GAB","GMB","GEO","DEU","GHA","GRC","GRL","GRD","GTM","GIN","GNB","GUY","HTI","HND","HKG","HUN","ISL","IND","IDN","IRN","IRQ","IRL","ISR","ITA","JAM","JPN","JOR","KAZ","KEN","KIR","KWT","KGZ","LAO","LVA","LBN","LSO","LBR","LBY","LIE","LTU","LUX","MAC","MDG","MWI","MYS","MDV","MLI","MLT","MHL","MRT","MUS","MEX","MDA","MNG","MNE","MAR","MOZ","MMR","NAM","NRU","NPL","NLD","NCL","NZL","NIC","NER","NGA","NIU","PRK","MKD","NOR","OMN","PAK","PAN","PNG","PRY","PER","PHL","POL","PRT","QAT","ROU","RUS","RWA","SHN","KNA","LCA","SPM","VCT","WSM","STP","SAU","SRB","SYC","SLE","SGP","SVK","SVN","SLB","SOM","KOR","SSD","ESP","LKA","SDN","SUR","SWE","CHE","SYR","TWN","TJK","TZA","THA","TLS","TGO","TON","TTO","TUN","TUR","TKM","TUV","UGA","UKR","ARE","GBR","USA","URY","UZB","VUT","VEN","VNM","YEM","ZMB","ZWE"],"Continent":["Asia","Europe","Africa","Europe","Africa","North America","North America","South America","Asia","North America","Oceania","Europe","Europe","North America","Asia","Asia","North America","Europe","Europe","North America","Africa","North America","Asia","South America","Europe","Africa","South America","North America","Asia","Europe","Africa","Africa","Asia","Africa","North America","Africa","Africa","Africa","South America","Asia","South America","Africa","Africa","Oceania","Central America","Europe","North America","Europe","Europe","Africa","Europe","Africa","North America","South America","Africa","Central America","Africa","Africa","Europe","Africa","Oceania","Europe","Europe","Oceania","Africa","Africa","Asia","Europe","Africa","Europe","North America","North America","Central America","Africa","Africa","South America","North America","Central America","Asia","Europe","Europe","Asia","Asia","Asia","Asia","Europe","Asia","Europe","North America","Asia","Asia","Asia","Africa","Oceania","Asia","Asia","Asia","Europe","Asia","Africa","Africa","Africa","Europe","Europe","Europe","Asia","Africa","Africa","Asia","Asia","Africa","Europe","Oceania","Africa","Africa","North America","Europe","Asia","Europe","Africa","Africa","Asia","Africa","Oceania","Asia","Europe","Oceania","Oceania","Central America","Africa","Africa","Oceania","Asia","Europe","Europe","Asia","Asia","Central America","Oceania","South America","South America","Asia","Europe","Europe","Africa","Europe","Asia","Africa","Africa","North America","North America","North America","North America","Oceania","Africa","Asia","Europe","Africa","Africa","Asia","Europe","Europe","Oceania","Africa","Asia","Africa","Europe","Asia","Africa","South America","Europe","Europe","Asia","Asia","Asia","Africa","Asia","Asia","Africa","Oceania","North America","Africa","Asia","Asia","Oceania","Africa","Europe","Asia","Europe","North America","South America","Asia","Oceania","South America","Asia","Asia","Africa","Africa"],"Country":["Afghanistan","Albania","Algeria","Andorra","Angola","Anguilla","Antigua & Barbuda","Argentina","Armenia","Aruba","Australia","Austria","Azerbaijan","Bahamas","Bahrain","Bangladesh","Barbados","Belarus","Belgium","Belize","Benin","Bermuda","Bhutan","Bolivia","Bosnia and Herzegovina","Botswana","Brazil","British Virgin Islands","Brunei Darussalam","Bulgaria","Burkina Faso","Burundi","Cambodia","Cameroon","Canada","Cape Verde","Central African Republic","Chad","Chile","China","Colombia","Comoros","Congo","Cook Islands","Costa Rica","Croatia","Cuba","Cyprus","Czechia","Democratic Republic of the Congo","Denmark","Djibouti","Dominican Republic","Ecuador","Egypt","El Salvador","Equatorial Guinea","Eritrea","Estonia","Ethiopia","Fiji","Finland","France","French Polynesia","Gabon","Gambia","Georgia","Germany","Ghana","Greece","Greenland","Grenada","Guatemala","Guinea","Guinea-Bissau","Guyana","Haiti","Honduras","Hong Kong","Hungary","Iceland","India","Indonesia","Iran","Iraq","Ireland","Israel","Italy","Jamaica","Japan","Jordan","Kazakhstan","Kenya","Kiribati","Kuwait","Kyrgyzstan","Lao People's Democratic Republic","Latvia","Lebanon","Lesotho","Liberia","Libya","Liechtenstein","Lithuania","Luxembourg","Macao","Madagascar","Malawi","Malaysia","Maldives","Mali","Malta","Marshall Islands","Mauritania","Mauritius","Mexico","Moldova","Mongolia","Montenegro","Morocco","Mozambique","Myanmar","Namibia","Nauru","Nepal","Netherlands","New Caledonia","New Zealand","Nicaragua","Niger","Nigeria","Niue","Democratic People's Republic of Korea","The former Yugoslav Republic of Macedonia","Norway","Oman","Pakistan","Panama","Papua New Guinea","Paraguay","Peru","Philippines","Poland","Portugal","Qatar","Romania","Russia","Rwanda","Saint Helena","Saint Kitts and Nevis","Saint Lucia","Saint Pierre and Miquelon","Saint Vincent and the Grenadines","Samoa","Sao Tome and Principe","Saudi Arabia","Serbia","Seychelles","Sierra Leone","Singapore","Slovakia","Slovenia","Solomon Islands","Somalia","Republic of Korea","South Sudan","Spain","Sri Lanka","Sudan","Suriname","Sweden","Switzerland","Syria","Taiwan","Tajikistan","Tanzania","Thailand","Timor-Leste","Togo","Tonga","Trinidad and Tobago","Tunisia","Turkey","Turkmenistan","Tuvalu","Uganda","Ukraine","United Arab Emirates","United Kingdom","United States","Uruguay","Uzbekistan","Vanuatu","Venezuela","Vietnam","Yemen","Zambia","Zimbabwe"],"Emissions":["Q4: 7.8 - 22.4","Q3: 2.69 - 7.8","Q6: 46 - 208","Q1: 0.00765 - 0.564","Q5: 22.4 - 46","Q1: 0.00765 - 0.564","Q1: 0.00765 - 0.564","Q6: 46 - 208","Q3: 2.69 - 7.8","Q2: 0.564 - 2.69","Q7: 208 - 9.96e+03","Q6: 46 - 208","Q5: 22.4 - 46","Q2: 0.564 - 2.69","Q5: 22.4 - 46","Q6: 46 - 208","Q2: 0.564 - 2.69","Q6: 46 - 208","Q6: 46 - 208","Q2: 0.564 - 2.69","Q3: 2.69 - 7.8","Q2: 0.564 - 2.69","Q2: 0.564 - 2.69","Q4: 7.8 - 22.4","Q4: 7.8 - 22.4","Q3: 2.69 - 7.8","Q7: 208 - 9.96e+03","Q1: 0.00765 - 0.564","Q4: 7.8 - 22.4","Q5: 22.4 - 46","Q3: 2.69 - 7.8","Q2: 0.564 - 2.69","Q4: 7.8 - 22.4","Q3: 2.69 - 7.8","Q7: 208 - 9.96e+03","Q2: 0.564 - 2.69","Q1: 0.00765 - 0.564","Q2: 0.564 - 2.69","Q6: 46 - 208","Q7: 208 - 9.96e+03","Q6: 46 - 208","Q1: 0.00765 - 0.564","Q3: 2.69 - 7.8","Q1: 0.00765 - 0.564","Q4: 7.8 - 22.4","Q4: 7.8 - 22.4","Q5: 22.4 - 46","Q3: 2.69 - 7.8","Q6: 46 - 208","Q2: 0.564 - 2.69","Q5: 22.4 - 46","Q1: 0.00765 - 0.564","Q5: 22.4 - 46","Q5: 22.4 - 46","Q7: 208 - 9.96e+03","Q3: 2.69 - 7.8","Q3: 2.69 - 7.8","Q2: 0.564 - 2.69","Q4: 7.8 - 22.4","Q4: 7.8 - 22.4","Q2: 0.564 - 2.69","Q5: 22.4 - 46","Q7: 208 - 9.96e+03","Q2: 0.564 - 2.69","Q3: 2.69 - 7.8","Q1: 0.00765 - 0.564","Q4: 7.8 - 22.4","Q7: 208 - 9.96e+03","Q4: 7.8 - 22.4","Q6: 46 - 208","Q1: 0.00765 - 0.564","Q1: 0.00765 - 0.564","Q4: 7.8 - 22.4","Q3: 2.69 - 7.8","Q1: 0.00765 - 0.564","Q2: 0.564 - 2.69","Q3: 2.69 - 7.8","Q4: 7.8 - 22.4","Q5: 22.4 - 46","Q6: 46 - 208","Q3: 2.69 - 7.8","Q7: 208 - 9.96e+03","Q7: 208 - 9.96e+03","Q7: 208 - 9.96e+03","Q7: 208 - 9.96e+03","Q5: 22.4 - 46","Q6: 46 - 208","Q7: 208 - 9.96e+03","Q4: 7.8 - 22.4","Q7: 208 - 9.96e+03","Q5: 22.4 - 46","Q7: 208 - 9.96e+03","Q4: 7.8 - 22.4","Q1: 0.00765 - 0.564","Q6: 46 - 208","Q4: 7.8 - 22.4","Q5: 22.4 - 46","Q4: 7.8 - 22.4","Q5: 22.4 - 46","Q2: 0.564 - 2.69","Q2: 0.564 - 2.69","Q5: 22.4 - 46","Q1: 0.00765 - 0.564","Q4: 7.8 - 22.4","Q4: 7.8 - 22.4","Q2: 0.564 - 2.69","Q3: 2.69 - 7.8","Q2: 0.564 - 2.69","Q7: 208 - 9.96e+03","Q2: 0.564 - 2.69","Q3: 2.69 - 7.8","Q2: 0.564 - 2.69","Q1: 0.00765 - 0.564","Q3: 2.69 - 7.8","Q3: 2.69 - 7.8","Q7: 208 - 9.96e+03","Q3: 2.69 - 7.8","Q6: 46 - 208","Q2: 0.564 - 2.69","Q6: 46 - 208","Q4: 7.8 - 22.4","Q5: 22.4 - 46","Q3: 2.69 - 7.8","Q1: 0.00765 - 0.564","Q4: 7.8 - 22.4","Q6: 46 - 208","Q4: 7.8 - 22.4","Q5: 22.4 - 46","Q3: 2.69 - 7.8","Q2: 0.564 - 2.69","Q6: 46 - 208","Q1: 0.00765 - 0.564","Q5: 22.4 - 46","Q3: 2.69 - 7.8","Q5: 22.4 - 46","Q6: 46 - 208","Q7: 208 - 9.96e+03","Q4: 7.8 - 22.4","Q3: 2.69 - 7.8","Q4: 7.8 - 22.4","Q6: 46 - 208","Q6: 46 - 208","Q7: 208 - 9.96e+03","Q6: 46 - 208","Q6: 46 - 208","Q6: 46 - 208","Q7: 208 - 9.96e+03","Q2: 0.564 - 2.69","Q1: 0.00765 - 0.564","Q1: 0.00765 - 0.564","Q1: 0.00765 - 0.564","Q1: 0.00765 - 0.564","Q1: 0.00765 - 0.564","Q1: 0.00765 - 0.564","Q1: 0.00765 - 0.564","Q7: 208 - 9.96e+03","Q6: 46 - 208","Q2: 0.564 - 2.69","Q2: 0.564 - 2.69","Q5: 22.4 - 46","Q5: 22.4 - 46","Q4: 7.8 - 22.4","Q1: 0.00765 - 0.564","Q2: 0.564 - 2.69","Q7: 208 - 9.96e+03","Q2: 0.564 - 2.69","Q7: 208 - 9.96e+03","Q5: 22.4 - 46","Q5: 22.4 - 46","Q2: 0.564 - 2.69","Q5: 22.4 - 46","Q5: 22.4 - 46","Q5: 22.4 - 46","Q7: 208 - 9.96e+03","Q3: 2.69 - 7.8","Q4: 7.8 - 22.4","Q7: 208 - 9.96e+03","Q1: 0.00765 - 0.564","Q3: 2.69 - 7.8","Q1: 0.00765 - 0.564","Q5: 22.4 - 46","Q5: 22.4 - 46","Q7: 208 - 9.96e+03","Q6: 46 - 208","Q1: 0.00765 - 0.564","Q3: 2.69 - 7.8","Q7: 208 - 9.96e+03","Q6: 46 - 208","Q7: 208 - 9.96e+03","Q7: 208 - 9.96e+03","Q3: 2.69 - 7.8","Q6: 46 - 208","Q1: 0.00765 - 0.564","Q6: 46 - 208","Q7: 208 - 9.96e+03","Q4: 7.8 - 22.4","Q3: 2.69 - 7.8","Q4: 7.8 - 22.4"]},"z":null},"config":{"graphType":"Map","isR":true,"colorBy":"CO2","topoJSON":"https://www.canvasxpress.org/data/maps/WORLD.json","mapId":"co2Linear","legendPosition":"left","theme":"solarized","title":"The same data on a plain linear ramp","subtitle":"195 of 198 countries sit in the bottom fifth of the scale - the map goes flat"},"events":null,"afterRender":null},"evals":[],"jsHooks":[]}</script>
</div>
</div>
<p>This is the single most common choropleth failure. The cure is <strong>classing</strong>:</p>
<ul>
<li><code>colorSpectrumBreaksMethod = "quantile"</code> — equal <em>counts</em> per class. Every colour is used, by construction. The right default for skewed data and for “which regions rank high/low” questions.</li>
<li><code>colorSpectrumBreaksMethod = "jenks"</code> — natural breaks that minimise within-class variance. Best when the data has genuine clusters with gaps between them; on smoothly heavy-tailed data like this it piles almost everything into the bottom class, so check the legend before you trust it.</li>
<li>Three to seven classes is the usable range — beyond that, readers cannot match colours to the legend.</li>
</ul>
</section>
<section id="choose-the-palette-on-purpose" class="level2">
<h2 class="anchored" data-anchor-id="choose-the-palette-on-purpose">Choose the palette on purpose</h2>
<p>The palette is not decoration — it is the scale’s grammar:</p>
<ul>
<li><p><strong>Sequential</strong> (dark → light of ordered hues, like viridis above) for a quantity that only goes up: counts, rates, concentrations.</p></li>
<li><p><strong>Diverging</strong> (two hues meeting at a neutral midpoint) when values are meaningful <em>above and below a reference</em>: change vs.&nbsp;last year, difference from a target, a signed index. Give canvasXpress a three-colour <code>colorSpectrum</code> and pin the midpoint with <code>colorSpectrumZeroValue</code>:</p>
<div class="sourceCode" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1">colorBy <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Change"</span>,</span>
<span id="cb11-2">colorSpectrum <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#2166ac"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#f7f7f7"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#b2182b"</span>),  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># blue - neutral - red</span></span>
<span id="cb11-3">colorSpectrumZeroValue <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>                               <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># value mapped to the middle colour</span></span></code></pre></div>
<p>Never use a diverging palette for a purely positive quantity — the neutral midpoint invents a “normal” that the data does not have.</p></li>
</ul>
<p>Viridis and the ColorBrewer ramps are colour-blind-safe and perceptually ordered; a rainbow ramp is neither, so readers cannot tell which end means “more”. Keep the <em>same</em> scale across small multiples so maps stay comparable.</p>
</section>
<section id="polish-legend-labels-and-base-styling" class="level2">
<h2 class="anchored" data-anchor-id="polish-legend-labels-and-base-styling">Polish: legend, labels and base styling</h2>
<ul>
<li><code>subtitle</code> / <code>source</code> — caption the units and provenance.</li>
<li><code>legendNumberFormat = list(style = "decimal", decimals = 1, suffix = "%")</code> — format the legend ticks as percentages, currency, etc.</li>
<li><code>mapColor</code> / <code>mapOutlineColor</code> — the fill for regions with <strong>no data</strong> (a neutral grey) and the border between shapes, so missing data reads as missing rather than as a value.</li>
<li><code>showMapLabels = TRUE</code> — draw region names (best on maps with few regions, e.g.&nbsp;a single country’s provinces; it clutters a 190-country world map).</li>
<li><code>legendInside = TRUE</code> — float the legend over empty ocean to reclaim width.</li>
</ul>
</section>
<section id="beyond-the-world-map" class="level2">
<h2 class="anchored" data-anchor-id="beyond-the-world-map">Beyond the world map</h2>
<ul>
<li><strong>Other boundaries.</strong> Point <code>topoJSON</code> at any shape file — US states, a single country’s regions, counties, custom districts. The join key is just the shape name.</li>
<li><strong>Projection.</strong> <code>mapProjection = "albers"</code> (equal-area, good for the US) or <code>"mercator"</code>. Equal-area projections matter for choropleths: Mercator inflates high latitudes, exaggerating those regions’ visual weight.</li>
<li><strong>Categorical maps.</strong> Point <code>colorBy</code> at a categorical column (an election winner, a priority tier) for a qualitative choropleth with a discrete legend.</li>
<li><strong>Markers.</strong> Add <code>decorations</code> to drop labelled points on cities or call out specific regions.</li>
</ul>
<p>The whole figure — data, boundaries, classing rule and palette — travels together as one spec, so a reviewer can reproduce it exactly and a colleague can re-render it from Python or JavaScript.</p>
</section>
<section id="next" class="level2">
<h2 class="anchored" data-anchor-id="next">Next</h2>
<ul>
<li><a href="../choropleth-maps-in-python/">Choropleth maps in Python</a></li>
<li><a href="../choropleth-maps-in-javascript/">Choropleth maps in JavaScript</a></li>
<li><a href="../clustered-heatmap-in-r/">Clustered heatmaps in R</a></li>
<li>Gallery: <a href="https://canvasxpress.org/examples.html" class="uri">https://canvasxpress.org/examples.html</a></li>
</ul>


</section>

 ]]></description>
  <category>R</category>
  <category>canvasXpress</category>
  <category>maps</category>
  <category>choropleth</category>
  <category>visualization</category>
  <guid>https://neuhausi.github.io/canvasxpress-blog/posts/r/choropleth-maps-in-r/</guid>
  <pubDate>Tue, 06 Oct 2026 04:00:00 GMT</pubDate>
  <media:content url="https://neuhausi.github.io/canvasxpress-blog/posts/r/choropleth-maps-in-r/thumbnail.png" medium="image" type="image/png" height="112" width="144"/>
</item>
<item>
  <title>Sankey / alluvial diagrams in R with canvasXpress</title>
  <dc:creator>Isaac Neuhaus</dc:creator>
  <link>https://neuhausi.github.io/canvasxpress-blog/posts/r/sankey-diagrams-in-r/</link>
  <description><![CDATA[ 




<p>A Sankey (or alluvial) diagram shows how a quantity <strong>flows through a sequence of categorical stages</strong> — patients moving from a cohort, to a treatment, to an outcome; or reads from a sample, to a mapping status, to a feature. The width of each stream is the magnitude. Here we build one in R with <a href="https://canvasxpress.org">canvasXpress</a> — interactive, and reproducible because the whole figure is one portable spec.</p>
<section id="the-data-shape" class="level2">
<h2 class="anchored" data-anchor-id="the-data-shape">The data shape</h2>
<p>canvasXpress builds a Sankey from a <strong>tidy table where each row is one path</strong> through the stages, plus a frequency/weight. Swap this simulated clinical flow for your own counts.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(canvasXpress)</span>
<span id="cb1-2"></span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set.seed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb1-4">cohort <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(); treat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(); outcome <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(); freq <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>()</span>
<span id="cb1-5"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (co <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cohort A"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cohort B"</span>))</span>
<span id="cb1-6"> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (tr <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Drug 1"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Drug 2"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Placebo"</span>))</span>
<span id="cb1-7">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (ou <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Response"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Stable"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Progression"</span>)) {</span>
<span id="cb1-8">    base <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (ou <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Response"</span>) <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">40</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (ou <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Stable"</span>) <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">15</span></span>
<span id="cb1-9">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (tr <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Placebo"</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> ou <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Response"</span>) base <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>          <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># placebo responds less</span></span>
<span id="cb1-10">    cohort  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(cohort, co); treat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(treat, tr); outcome <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(outcome, ou)</span>
<span id="cb1-11">    freq    <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(freq, base <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">15</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))</span>
<span id="cb1-12">  }</span></code></pre></div>
</div>
<p>The value (<code>Freq</code>) is the single measured variable; the stage columns are sample annotations. In canvasXpress terms: one variable × N path-rows, with the categorical stages as <code>smpAnnot</code>.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">ids <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"r"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq_along</span>(freq))</span>
<span id="cb2-2">y <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matrix</span>(freq, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nrow =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dimnames =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Freq"</span>, ids)), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">check.names =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span>
<span id="cb2-3">smpAnnot <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Cohort =</span> cohort, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Treatment =</span> treat, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Outcome =</span> outcome,</span>
<span id="cb2-4">                       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">row.names =</span> ids, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">check.names =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span></code></pre></div>
</div>
</section>
<section id="the-plot" class="level2">
<h2 class="anchored" data-anchor-id="the-plot">The plot</h2>
<p><code>graphType = "Sankey"</code> with <code>sankeyAxes</code> listing the stages in order, <code>xAxis</code> naming the value, and <code>colorBy</code> coloring the streams.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">canvasXpress</span>(</span>
<span id="cb3-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data     =</span> y,</span>
<span id="cb3-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">smpAnnot =</span> smpAnnot,</span>
<span id="cb3-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">graphType =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Sankey"</span>,</span>
<span id="cb3-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sankeyAxes =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cohort"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Treatment"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Outcome"</span>),</span>
<span id="cb3-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xAxis      =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Freq"</span>),</span>
<span id="cb3-7">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colorBy    =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Outcome"</span>,</span>
<span id="cb3-8">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sankeyType =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"proportional"</span>,</span>
<span id="cb3-9">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">graphOrientation =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"horizontal"</span>,</span>
<span id="cb3-10">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Patient flow: cohort → treatment → outcome"</span>,</span>
<span id="cb3-11">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width  =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">700</span>,</span>
<span id="cb3-12">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">height =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500</span></span>
<span id="cb3-13">)</span></code></pre></div>
<div class="cell-output-display">
<div id="htmlwidget-4906484ed42468d86de4" style="width:100%;height:464px;" class="canvasXpress html-widget"></div>
<script type="application/json" data-for="htmlwidget-4906484ed42468d86de4">{"x":{"data":{"y":{"vars":["Freq"],"smps":["r1","r2","r3","r4","r5","r6","r7","r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18"],"data":[[48,28,21,40,26,27,18,35,28,41,35,17,40,29,19,21,30,28]]},"x":{"Cohort":["Cohort A","Cohort A","Cohort A","Cohort A","Cohort A","Cohort A","Cohort A","Cohort A","Cohort A","Cohort B","Cohort B","Cohort B","Cohort B","Cohort B","Cohort B","Cohort B","Cohort B","Cohort B"],"Treatment":["Drug 1","Drug 1","Drug 1","Drug 2","Drug 2","Drug 2","Placebo","Placebo","Placebo","Drug 1","Drug 1","Drug 1","Drug 2","Drug 2","Drug 2","Placebo","Placebo","Placebo"],"Outcome":["Response","Stable","Progression","Response","Stable","Progression","Response","Stable","Progression","Response","Stable","Progression","Response","Stable","Progression","Response","Stable","Progression"]},"z":null},"config":{"graphType":"Sankey","isR":true,"sankeyAxes":["Cohort","Treatment","Outcome"],"xAxis":["Freq"],"colorBy":"Outcome","sankeyType":"proportional","graphOrientation":"horizontal","title":"Patient flow: cohort → treatment → outcome"},"events":null,"afterRender":null},"evals":[],"jsHooks":[]}</script>
</div>
</div>
<p>Hover any stream to see the count; the widths are proportional to the frequency, so you can read the flow at a glance — e.g.&nbsp;how much of each cohort ends in Response vs Progression, and how Placebo differs. <code>sankeyType</code> can also be <code>"aligned"</code> (classic alluvial) or <code>"equal"</code>.</p>
</section>
<section id="why-reproducible" class="level2">
<h2 class="anchored" data-anchor-id="why-reproducible">Why “reproducible”</h2>
<p>The <code>data</code>+<code>config</code> <strong>is</strong> the figure — one portable JSON spec. The same spec renders the identical Sankey from Python or JavaScript, and can be validated and re-rendered later.</p>
</section>
<section id="next" class="level2">
<h2 class="anchored" data-anchor-id="next">Next</h2>
<ul>
<li><a href="../volcano-plots-in-r/">Interactive volcano plots in R</a></li>
<li>Gallery: <a href="https://canvasxpress.org/examples.html" class="uri">https://canvasxpress.org/examples.html</a></li>
<li>Package: <a href="https://github.com/neuhausi/canvasXpress" class="uri">https://github.com/neuhausi/canvasXpress</a></li>
</ul>


</section>

 ]]></description>
  <category>R</category>
  <category>canvasXpress</category>
  <category>sankey</category>
  <category>visualization</category>
  <guid>https://neuhausi.github.io/canvasxpress-blog/posts/r/sankey-diagrams-in-r/</guid>
  <pubDate>Sat, 26 Sep 2026 04:00:00 GMT</pubDate>
  <media:content url="https://neuhausi.github.io/canvasxpress-blog/posts/r/sankey-diagrams-in-r/thumbnail.png" medium="image" type="image/png" height="108" width="144"/>
</item>
<item>
  <title>Violin and half (split) violin plots in R with canvasXpress</title>
  <dc:creator>Isaac Neuhaus</dc:creator>
  <link>https://neuhausi.github.io/canvasxpress-blog/posts/r/violin-plots-in-r/</link>
  <description><![CDATA[ 




<p>A violin plot shows the <strong>full shape of a distribution</strong> — where the density is thick or thin — instead of collapsing it to a box’s quartiles. And when you want to compare two conditions at the same position, a <strong>split (half) violin</strong> puts one condition on each half. Here we build both in R with <a href="https://canvasxpress.org">canvasXpress</a>: interactive, and reproducible because the figure is one portable spec.</p>
<section id="the-data" class="level2">
<h2 class="anchored" data-anchor-id="the-data">The data</h2>
<p>A measurement across a few dose groups and two conditions. Swap in your own long-format table.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(canvasXpress)</span>
<span id="cb1-2"></span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set.seed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb1-4">doses <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Low"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Medium"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"High"</span>); conds <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Control"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Treated"</span>)</span>
<span id="cb1-5">value <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(); Dose <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(); Condition <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>()</span>
<span id="cb1-6"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (d <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> doses) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (co <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> conds) {</span>
<span id="cb1-7">  mu <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (d <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Low"</span>) <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (d <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Medium"</span>) <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span></span>
<span id="cb1-8">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (co <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Treated"</span>) mu <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mu <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.5</span></span>
<span id="cb1-9">  value <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(value, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rnorm</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">40</span>, mu, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.2</span>), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>))</span>
<span id="cb1-10">  Dose <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Dose, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(d, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">40</span>)); Condition <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Condition, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(co, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">40</span>))</span>
<span id="cb1-11">}</span></code></pre></div>
</div>
<p>In canvasXpress terms a violin is a <code>Boxplot</code> graph with the violin turned on: one measured variable × N observations, with the grouping columns as <code>smpAnnot</code>.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">ids <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"o"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq_along</span>(value))</span>
<span id="cb2-2">y <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matrix</span>(value, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nrow =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dimnames =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"value"</span>, ids)), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">check.names =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span>
<span id="cb2-3">smpAnnot <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Dose =</span> Dose, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Condition =</span> Condition, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">row.names =</span> ids, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">check.names =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span></code></pre></div>
</div>
</section>
<section id="a-full-violin-per-group" class="level2">
<h2 class="anchored" data-anchor-id="a-full-violin-per-group">A full violin per group</h2>
<p><code>showViolinBoxplot = TRUE</code> draws the violin (with a small boxplot inside); <code>violinScale = "area"</code> makes equal-area violins.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">canvasXpress</span>(</span>
<span id="cb3-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> y, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">smpAnnot =</span> smpAnnot, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">graphType =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Boxplot"</span>,</span>
<span id="cb3-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">showViolinBoxplot =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">violinScale =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"area"</span>,</span>
<span id="cb3-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">groupingFactors =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Dose"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xAxis =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"value"</span>),</span>
<span id="cb3-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">smpTitle =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Dose"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Distribution of value by dose"</span>,</span>
<span id="cb3-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">650</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">height =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500</span></span>
<span id="cb3-7">)</span></code></pre></div>
<div class="cell-output-display">
<div id="htmlwidget-a3c87662a2939578a855" style="width:100%;height:500px;" class="canvasXpress html-widget"></div>
<script type="application/json" data-for="htmlwidget-a3c87662a2939578a855">{"x":{"data":{"y":{"vars":["value"],"smps":["o1","o2","o3","o4","o5","o6","o7","o8","o9","o10","o11","o12","o13","o14","o15","o16","o17","o18","o19","o20","o21","o22","o23","o24","o25","o26","o27","o28","o29","o30","o31","o32","o33","o34","o35","o36","o37","o38","o39","o40","o41","o42","o43","o44","o45","o46","o47","o48","o49","o50","o51","o52","o53","o54","o55","o56","o57","o58","o59","o60","o61","o62","o63","o64","o65","o66","o67","o68","o69","o70","o71","o72","o73","o74","o75","o76","o77","o78","o79","o80","o81","o82","o83","o84","o85","o86","o87","o88","o89","o90","o91","o92","o93","o94","o95","o96","o97","o98","o99","o100","o101","o102","o103","o104","o105","o106","o107","o108","o109","o110","o111","o112","o113","o114","o115","o116","o117","o118","o119","o120","o121","o122","o123","o124","o125","o126","o127","o128","o129","o130","o131","o132","o133","o134","o135","o136","o137","o138","o139","o140","o141","o142","o143","o144","o145","o146","o147","o148","o149","o150","o151","o152","o153","o154","o155","o156","o157","o158","o159","o160","o161","o162","o163","o164","o165","o166","o167","o168","o169","o170","o171","o172","o173","o174","o175","o176","o177","o178","o179","o180","o181","o182","o183","o184","o185","o186","o187","o188","o189","o190","o191","o192","o193","o194","o195","o196","o197","o198","o199","o200","o201","o202","o203","o204","o205","o206","o207","o208","o209","o210","o211","o212","o213","o214","o215","o216","o217","o218","o219","o220","o221","o222","o223","o224","o225","o226","o227","o228","o229","o230","o231","o232","o233","o234","o235","o236","o237","o238","o239","o240"],"data":[[5.25,6.22,5,7.91,6.4,5.02,6.58,6.89,6.69,5.63,7.81,6.47,5.25,3.34,7.35,5.95,5.98,7.13,6.99,6.71,7.1,6.94,6.09,3.61,6.74,5.93,5.81,4.24,5.43,6.5,7.63,5.88,6.47,5.94,4.35,5.5,5.53,5.93,7.32,6.92,7.3,7.2,8.34,8.17,6.67,6.65,7.94,8.42,7.37,8.56,7.98,6.77,7.91,6.14,9.22,9.88,7.06,6.25,8.18,7.34,10.38,7.45,8.33,7.53,6.61,7.73,5.33,9.26,7.68,10.11,8.07,6.65,8.23,6.38,6,7.85,6.97,7.5,7.59,6.79,7.32,7.84,9.41,6.17,8.71,8.4,9.28,7.63,8.44,8.32,7.35,9.45,9.39,8.84,9.9,8.67,6.47,7.31,6.53,7.43,7.26,8.05,6.91,8.19,7.21,10.12,8.86,9.09,8.46,10.02,7.24,7.45,9.72,7.22,7.75,7.53,7.62,7.67,8.59,7.79,8.89,11.11,9.24,9.28,9.38,10.36,9.41,9.45,8.68,9.11,9.57,8.79,10.14,7.68,9.87,7.66,9.14,8.87,8.72,9.43,7.2,10.91,7.5,8.94,8.16,8.6,12,9.52,7.96,7.53,10.04,9.48,9.12,8.38,7.72,8.21,10.7,8.75,7.84,11.74,10.51,9.71,11.27,11.06,9.26,12.65,9.69,8.29,9.83,10.25,12.77,10.13,10.55,9.91,9.6,9.96,10.95,12.49,11.23,11.45,8.52,11.18,10.26,8.24,10.63,9.81,11.76,9.08,9.48,8.89,9.79,10.48,9.12,11,8.55,8.74,11.73,8.78,10.49,9.54,11.99,13.53,13.4,11.1,8.76,14.5,12.3,12.15,11.48,12.11,11.3,12,11.02,9.86,12.69,13.32,11.13,10,12.27,11.45,9.42,11.5,10.74,11.09,10.11,13.66,11.1,9.57,11.74,11.82,10.32,8.03,10.73,12.18,11.43,11.38,12.17,10.08,12.82,11.49]]},"x":{"Dose":["Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High"],"Condition":["Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated"]},"z":null},"config":{"graphType":"Boxplot","isR":true,"showViolinBoxplot":true,"violinScale":"area","groupingFactors":["Dose"],"xAxis":["value"],"smpTitle":"Dose","title":"Distribution of value by dose"},"events":null,"afterRender":null},"evals":[],"jsHooks":[]}</script>
</div>
</div>
</section>
<section id="a-split-half-violin-comparing-two-conditions" class="level2">
<h2 class="anchored" data-anchor-id="a-split-half-violin-comparing-two-conditions">A split (half) violin comparing two conditions</h2>
<p>Group by <strong>both</strong> factors, colour by the condition, and set <code>violinSide = "split"</code> — the two conditions share each dose position, one on each half. This reads far better than two full violins side by side.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">canvasXpress</span>(</span>
<span id="cb4-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> y, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">smpAnnot =</span> smpAnnot, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">graphType =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Boxplot"</span>,</span>
<span id="cb4-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">showViolinBoxplot =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">violinScale =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"area"</span>,</span>
<span id="cb4-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">groupingFactors =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Dose"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Condition"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colorBy =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Condition"</span>,</span>
<span id="cb4-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">violinSide =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"split"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">violinTrim =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xAxis =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"value"</span>),</span>
<span id="cb4-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">smpTitle =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Dose"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Control vs Treated — split violin by dose"</span>,</span>
<span id="cb4-7">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">650</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">height =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500</span></span>
<span id="cb4-8">)</span></code></pre></div>
<div class="cell-output-display">
<div id="htmlwidget-d26bfe112ba61c5aa31f" style="width:100%;height:500px;" class="canvasXpress html-widget"></div>
<script type="application/json" data-for="htmlwidget-d26bfe112ba61c5aa31f">{"x":{"data":{"y":{"vars":["value"],"smps":["o1","o2","o3","o4","o5","o6","o7","o8","o9","o10","o11","o12","o13","o14","o15","o16","o17","o18","o19","o20","o21","o22","o23","o24","o25","o26","o27","o28","o29","o30","o31","o32","o33","o34","o35","o36","o37","o38","o39","o40","o41","o42","o43","o44","o45","o46","o47","o48","o49","o50","o51","o52","o53","o54","o55","o56","o57","o58","o59","o60","o61","o62","o63","o64","o65","o66","o67","o68","o69","o70","o71","o72","o73","o74","o75","o76","o77","o78","o79","o80","o81","o82","o83","o84","o85","o86","o87","o88","o89","o90","o91","o92","o93","o94","o95","o96","o97","o98","o99","o100","o101","o102","o103","o104","o105","o106","o107","o108","o109","o110","o111","o112","o113","o114","o115","o116","o117","o118","o119","o120","o121","o122","o123","o124","o125","o126","o127","o128","o129","o130","o131","o132","o133","o134","o135","o136","o137","o138","o139","o140","o141","o142","o143","o144","o145","o146","o147","o148","o149","o150","o151","o152","o153","o154","o155","o156","o157","o158","o159","o160","o161","o162","o163","o164","o165","o166","o167","o168","o169","o170","o171","o172","o173","o174","o175","o176","o177","o178","o179","o180","o181","o182","o183","o184","o185","o186","o187","o188","o189","o190","o191","o192","o193","o194","o195","o196","o197","o198","o199","o200","o201","o202","o203","o204","o205","o206","o207","o208","o209","o210","o211","o212","o213","o214","o215","o216","o217","o218","o219","o220","o221","o222","o223","o224","o225","o226","o227","o228","o229","o230","o231","o232","o233","o234","o235","o236","o237","o238","o239","o240"],"data":[[5.25,6.22,5,7.91,6.4,5.02,6.58,6.89,6.69,5.63,7.81,6.47,5.25,3.34,7.35,5.95,5.98,7.13,6.99,6.71,7.1,6.94,6.09,3.61,6.74,5.93,5.81,4.24,5.43,6.5,7.63,5.88,6.47,5.94,4.35,5.5,5.53,5.93,7.32,6.92,7.3,7.2,8.34,8.17,6.67,6.65,7.94,8.42,7.37,8.56,7.98,6.77,7.91,6.14,9.22,9.88,7.06,6.25,8.18,7.34,10.38,7.45,8.33,7.53,6.61,7.73,5.33,9.26,7.68,10.11,8.07,6.65,8.23,6.38,6,7.85,6.97,7.5,7.59,6.79,7.32,7.84,9.41,6.17,8.71,8.4,9.28,7.63,8.44,8.32,7.35,9.45,9.39,8.84,9.9,8.67,6.47,7.31,6.53,7.43,7.26,8.05,6.91,8.19,7.21,10.12,8.86,9.09,8.46,10.02,7.24,7.45,9.72,7.22,7.75,7.53,7.62,7.67,8.59,7.79,8.89,11.11,9.24,9.28,9.38,10.36,9.41,9.45,8.68,9.11,9.57,8.79,10.14,7.68,9.87,7.66,9.14,8.87,8.72,9.43,7.2,10.91,7.5,8.94,8.16,8.6,12,9.52,7.96,7.53,10.04,9.48,9.12,8.38,7.72,8.21,10.7,8.75,7.84,11.74,10.51,9.71,11.27,11.06,9.26,12.65,9.69,8.29,9.83,10.25,12.77,10.13,10.55,9.91,9.6,9.96,10.95,12.49,11.23,11.45,8.52,11.18,10.26,8.24,10.63,9.81,11.76,9.08,9.48,8.89,9.79,10.48,9.12,11,8.55,8.74,11.73,8.78,10.49,9.54,11.99,13.53,13.4,11.1,8.76,14.5,12.3,12.15,11.48,12.11,11.3,12,11.02,9.86,12.69,13.32,11.13,10,12.27,11.45,9.42,11.5,10.74,11.09,10.11,13.66,11.1,9.57,11.74,11.82,10.32,8.03,10.73,12.18,11.43,11.38,12.17,10.08,12.82,11.49]]},"x":{"Dose":["Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Low","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","Medium","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High","High"],"Condition":["Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Control","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated","Treated"]},"z":null},"config":{"graphType":"Boxplot","isR":true,"showViolinBoxplot":true,"violinScale":"area","groupingFactors":["Dose","Condition"],"colorBy":"Condition","violinSide":"split","violinTrim":false,"xAxis":["value"],"smpTitle":"Dose","title":"Control vs Treated — split violin by dose"},"events":null,"afterRender":null},"evals":[],"jsHooks":[]}</script>
</div>
</div>
<p>Hover to read the density and summary stats. <code>violinSide</code> can also be <code>"lt"</code> or <code>"rb"</code> for a one-sided half violin (handy for a raincloud when paired with <code>violinPointsSide</code>).</p>
</section>
<section id="why-reproducible" class="level2">
<h2 class="anchored" data-anchor-id="why-reproducible">Why “reproducible”</h2>
<p>The <code>data</code>+<code>config</code> <strong>is</strong> the figure — one portable JSON spec that renders the identical violins from Python or JavaScript, and can be validated and re-rendered later.</p>
</section>
<section id="next" class="level2">
<h2 class="anchored" data-anchor-id="next">Next</h2>
<ul>
<li><a href="../volcano-plots-in-r/">Interactive volcano plots in R</a></li>
<li><a href="../paired-boxplots/">Paired before/after boxplots in R</a></li>
<li>Gallery: <a href="https://canvasxpress.org/examples.html" class="uri">https://canvasxpress.org/examples.html</a></li>
</ul>


</section>

 ]]></description>
  <category>R</category>
  <category>canvasXpress</category>
  <category>violin</category>
  <category>visualization</category>
  <guid>https://neuhausi.github.io/canvasxpress-blog/posts/r/violin-plots-in-r/</guid>
  <pubDate>Fri, 25 Sep 2026 04:00:00 GMT</pubDate>
  <media:content url="https://neuhausi.github.io/canvasxpress-blog/posts/r/violin-plots-in-r/thumbnail.png" medium="image" type="image/png" height="108" width="144"/>
</item>
<item>
  <title>Paired before/after boxplots in R with canvasXpress</title>
  <dc:creator>Isaac Neuhaus</dc:creator>
  <link>https://neuhausi.github.io/canvasxpress-blog/posts/r/paired-boxplots/</link>
  <description><![CDATA[ 




<p>When the same subjects are measured twice — before/after a treatment, baseline vs follow-up — a <strong>paired boxplot</strong> with a line connecting each subject across the two timepoints tells the story a plain boxplot can’t. This post builds one in R by wrapping a <a href="https://rpkgs.datanovia.com/ggpubr/">ggpubr</a> <code>ggpaired</code> plot with <a href="https://canvasxpress.org">canvasXpress</a>, so it becomes interactive and reproducible without re-specifying anything.</p>
<section id="install" class="level2">
<h2 class="anchored" data-anchor-id="install">Install</h2>
<div class="cell">
<div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">install.packages</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"canvasXpress"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ggpubr"</span>))</span></code></pre></div>
</div>
</section>
<section id="a-paired-dataset" class="level2">
<h2 class="anchored" data-anchor-id="a-paired-dataset">A paired dataset</h2>
<p>Long format, two rows per subject — one per timepoint. Swap in your own repeated-measures table.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(ggplot2)</span>
<span id="cb2-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(ggpubr)</span>
<span id="cb2-3"></span>
<span id="cb2-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set.seed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">7</span>)</span>
<span id="cb2-5">n  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span></span>
<span id="cb2-6">df <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(</span>
<span id="cb2-7">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">id    =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"P"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq_len</span>(n)), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>),</span>
<span id="cb2-8">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">time  =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Baseline"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Week 12"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">each =</span> n),</span>
<span id="cb2-9">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rnorm</span>(n, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.2</span>),                       <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># baseline</span></span>
<span id="cb2-10">            <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rnorm</span>(n, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rnorm</span>(n, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.2</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8</span>)) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># follow-up (a drop)</span></span>
<span id="cb2-11">)</span></code></pre></div>
</div>
</section>
<section id="build-it-with-ggpaired-then-wrap-it" class="level2">
<h2 class="anchored" data-anchor-id="build-it-with-ggpaired-then-wrap-it">Build it with ggpaired, then wrap it</h2>
<p><code>ggpaired</code> draws the two boxes and the per-subject connecting lines; <code>stat_compare_means</code> adds a paired test. Then hand the whole thing to <code>canvasXpress()</code>:</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(canvasXpress)</span>
<span id="cb3-2"></span>
<span id="cb3-3">g <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggpaired</span>(</span>
<span id="cb3-4">  df, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"time"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"value"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">id =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"id"</span>,</span>
<span id="cb3-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"time"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">line.color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"gray"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">line.size =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3</span></span>
<span id="cb3-6">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stat_compare_means</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">paired =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">method =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"t.test"</span>)</span>
<span id="cb3-8"></span>
<span id="cb3-9"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">canvasXpress</span>(g)</span></code></pre></div>
<div class="cell-output-display">
<div id="htmlwidget-aa56dee1de73a15107a4" style="width:100%;height:433px;" class="canvasXpress html-widget"></div>
<script type="application/json" data-for="htmlwidget-aa56dee1de73a15107a4">{"x":{
  "renderTo": "canvas",
  "data": [
    ["Id", "id", "time", "value"],
    ["1", "P1", "Baseline", "10.7446965936086"],
    ["2", "P2", "Baseline", "6.56387398133318"],
    ["3", "P3", "Baseline", "7.16684898747745"],
    ["4", "P4", "Baseline", "7.50524845863584"],
    ["5", "P5", "Baseline", "6.83519199065662"],
    ["6", "P6", "Baseline", "6.86326406572627"],
    ["7", "P7", "Baseline", "8.89776720834866"],
    ["8", "P8", "Baseline", "7.85965372893542"],
    ["9", "P9", "Baseline", "8.18318915153868"],
    ["10", "P10", "Baseline", "10.6279737287953"],
    ["11", "P11", "Baseline", "8.42838347639483"],
    ["12", "P12", "Baseline", "11.2601021397569"],
    ["13", "P13", "Baseline", "10.7377423111875"],
    ["14", "P14", "Baseline", "8.38882464816622"],
    ["15", "P15", "Baseline", "10.2752804801719"],
    ["16", "P16", "Baseline", "8.56121661358604"],
    ["17", "P17", "Baseline", "6.92743913229747"],
    ["18", "P18", "Baseline", "7.63120604055537"],
    ["19", "P19", "Baseline", "7.99421309327892"],
    ["20", "P20", "Baseline", "9.18579697939993"],
    ["21", "P21", "Baseline", "9.00770043154889"],
    ["22", "P22", "Baseline", "8.8464101970866"],
    ["23", "P23", "Baseline", "9.56715766497403"],
    ["24", "P24", "Baseline", "6.33440454008858"],
    ["25", "P25", "Baseline", "9.52750023710628"],
    ["26", "P1", "Week 12", "6.81083744662969"],
    ["27", "P2", "Week 12", "7.69660139111791"],
    ["28", "P3", "Week 12", "7.80381646819178"],
    ["29", "P4", "Week 12", "6.98606692118486"],
    ["30", "P5", "Week 12", "7.0477154638883"],
    ["31", "P6", "Week 12", "6.13980761188402"],
    ["32", "P7", "Week 12", "6.40815806832089"],
    ["33", "P8", "Week 12", "7.18738368010787"],
    ["34", "P9", "Week 12", "6.83863303897584"],
    ["35", "P10", "Week 12", "5.57548534508707"],
    ["36", "P11", "Week 12", "6.18654612754614"],
    ["37", "P12", "Week 12", "8.12434035631655"],
    ["38", "P13", "Week 12", "5.90878327719184"],
    ["39", "P14", "Week 12", "7.19310048516094"],
    ["40", "P15", "Week 12", "7.43316919991118"],
    ["41", "P16", "Week 12", "9.14966047258566"],
    ["42", "P17", "Week 12", "6.57614286130307"],
    ["43", "P18", "Week 12", "7.38025963798868"],
    ["44", "P19", "Week 12", "6.23468359501349"],
    ["45", "P20", "Week 12", "6.89128388751875"],
    ["46", "P21", "Week 12", "6.6642697929628"],
    ["47", "P22", "Week 12", "7.68253972250201"],
    ["48", "P23", "Week 12", "7.01696066720233"],
    ["49", "P24", "Week 12", "6.22730279615318"],
    ["50", "P25", "Week 12", "6.60567272487921"]
  ],
  "aes": {
    "x": "time",
    "y": "value"
  },
  "mappings": {
    "x": true,
    "y": false
  },
  "scales": {
    "colors": ["#F8766D", "#00BFC4"],
    "sizes": 6
  },
  "coords": [],
  "theme": {
    "axis.line.arrow": "FALSE",
    "axis.line.arrow.fill": "black",
    "axis.line.colour": "black",
    "axis.line.linewidth": "0.5",
    "axis.minor.ticks.length": "0.75",
    "axis.text.colour": "black",
    "axis.text.fontweight": null,
    "axis.text.fontwidth": null,
    "axis.text.italic": null,
    "axis.text.r.fontweight": null,
    "axis.text.r.fontwidth": null,
    "axis.text.r.hjust": "0.5",
    "axis.text.r.italic": null,
    "axis.text.r.margin": 2.4,
    "axis.text.x.fontweight": null,
    "axis.text.x.fontwidth": null,
    "axis.text.x.italic": null,
    "axis.text.x.margin": 2.4,
    "axis.text.x.vjust": "1",
    "axis.text.x.top.fontweight": null,
    "axis.text.x.top.fontwidth": null,
    "axis.text.x.top.italic": null,
    "axis.text.x.top.margin": 2.4,
    "axis.text.x.top.vjust": "0",
    "axis.text.y.fontweight": null,
    "axis.text.y.fontwidth": null,
    "axis.text.y.hjust": "1",
    "axis.text.y.italic": null,
    "axis.text.y.margin": 2.4,
    "axis.text.y.right.fontweight": null,
    "axis.text.y.right.fontwidth": null,
    "axis.text.y.right.hjust": "0",
    "axis.text.y.right.italic": null,
    "axis.text.y.right.margin": 2.4,
    "axis.ticks.arrow": "FALSE",
    "axis.ticks.arrow.fill": "black",
    "axis.ticks.colour": "black",
    "axis.ticks.length": "0.5",
    "axis.title.x.fontweight": null,
    "axis.title.x.fontwidth": null,
    "axis.title.x.italic": null,
    "axis.title.x.margin": 3,
    "axis.title.x.vjust": "1",
    "axis.title.x.top.fontweight": null,
    "axis.title.x.top.fontwidth": null,
    "axis.title.x.top.italic": null,
    "axis.title.x.top.margin": 3,
    "axis.title.x.top.vjust": "0",
    "axis.title.y.angle": "90",
    "axis.title.y.fontweight": null,
    "axis.title.y.fontwidth": null,
    "axis.title.y.italic": null,
    "axis.title.y.margin": 3,
    "axis.title.y.vjust": "1",
    "axis.title.y.right.angle": "-90",
    "axis.title.y.right.fontweight": null,
    "axis.title.y.right.fontwidth": null,
    "axis.title.y.right.italic": null,
    "axis.title.y.right.margin": 3,
    "axis.title.y.right.vjust": "1",
    "geom.accent": "#3366FF",
    "geom.bordertype": "1",
    "geom.borderwidth": "0.545454545454545",
    "geom.family": "",
    "geom.fontsize": "4.21751764217518",
    "geom.ink": "black",
    "geom.linetype": "1",
    "geom.linewidth": "0.545454545454545",
    "geom.paper": "white",
    "geom.pointshape": "19",
    "geom.pointsize": "1.63636363636364",
    "legend.background.colour": null,
    "legend.box.background": "element_blank",
    "legend.box.margin": "margin",
    "legend.box.spacing": "2",
    "legend.justification": "center",
    "legend.key": "element_blank",
    "legend.key.size": "1.2lines",
    "legend.position": "top",
    "legend.spacing": "2",
    "legend.text.fontweight": null,
    "legend.text.fontwidth": null,
    "legend.text.italic": null,
    "legend.text.size": 9,
    "legend.ticks.length": "0.2",
    "legend.title.fontweight": null,
    "legend.title.fontwidth": null,
    "legend.title.hjust": "0",
    "legend.title.italic": null,
    "line.arrow": "FALSE",
    "line.arrow.fill": "black",
    "line.colour": "black",
    "line.lineend": "butt",
    "line.linejoin": "round",
    "line.linetype": "1",
    "line.linewidth": "0.545454545454545",
    "margins": "margin",
    "panel.background.colour": null,
    "panel.background.fill": "white",
    "panel.border": "element_blank",
    "panel.grid.arrow": "FALSE",
    "panel.grid.arrow.fill": "#EBEBEBFF",
    "panel.grid.colour": "#EBEBEBFF",
    "panel.grid.major": "element_blank",
    "panel.grid.minor": "element_blank",
    "panel.ontop": "FALSE",
    "plot.background.colour": "white",
    "plot.caption.fontweight": null,
    "plot.caption.fontwidth": null,
    "plot.caption.hjust": "1",
    "plot.caption.italic": null,
    "plot.caption.margin": 6,
    "plot.caption.size": 9,
    "plot.caption.vjust": "1",
    "plot.caption.position": "panel",
    "plot.margin": "margin",
    "plot.subtitle.fontweight": null,
    "plot.subtitle.fontwidth": null,
    "plot.subtitle.hjust": "0",
    "plot.subtitle.italic": null,
    "plot.subtitle.margin": 6,
    "plot.subtitle.vjust": "1",
    "plot.tag.fontweight": null,
    "plot.tag.fontwidth": null,
    "plot.tag.hjust": "0.5",
    "plot.tag.italic": null,
    "plot.tag.size": 13,
    "plot.tag.vjust": "0.5",
    "plot.tag.position": "topleft",
    "plot.title.fontweight": null,
    "plot.title.fontwidth": null,
    "plot.title.hjust": "0",
    "plot.title.italic": null,
    "plot.title.margin": 6,
    "plot.title.size": 13,
    "plot.title.vjust": "1",
    "plot.title.position": "panel",
    "point.colour": "black",
    "point.fill": "white",
    "point.shape": "19",
    "point.size": "1.63636363636364",
    "point.stroke": "0.545454545454545",
    "polygon.colour": "black",
    "polygon.fill": "white",
    "polygon.linejoin": "round",
    "polygon.linetype": "1",
    "polygon.linewidth": "0.545454545454545",
    "rect.colour": "black",
    "rect.fill": "white",
    "rect.linejoin": "round",
    "rect.linetype": "1",
    "rect.linewidth": "0.545454545454545",
    "spacing": "6",
    "strip.background.colour": "black",
    "strip.background.fill": "#F2F2F2",
    "strip.background.linewidth": "0.7",
    "strip.clip": "on",
    "strip.placement": "inside",
    "strip.switch.pad.grid": "3",
    "strip.switch.pad.wrap": "3",
    "strip.text.colour": "#1A1A1AFF",
    "strip.text.fontweight": null,
    "strip.text.fontwidth": null,
    "strip.text.italic": null,
    "strip.text.margin": 4.8,
    "strip.text.size": 9,
    "strip.text.y.angle": "-90",
    "strip.text.y.fontweight": null,
    "strip.text.y.fontwidth": null,
    "strip.text.y.italic": null,
    "strip.text.y.left.angle": "90",
    "strip.text.y.left.fontweight": null,
    "strip.text.y.left.fontwidth": null,
    "strip.text.y.left.italic": null,
    "text.angle": "0",
    "text.colour": "black",
    "text.debug": "FALSE",
    "text.face": "plain",
    "text.family": "",
    "text.fontweight": null,
    "text.fontwidth": null,
    "text.hjust": "0.5",
    "text.italic": null,
    "text.lineheight": "0.9",
    "text.margin": 0,
    "text.size": "12",
    "text.vjust": "0.5",
    "title.fontweight": null,
    "title.fontwidth": null,
    "title.italic": null
  },
  "labels": {
    "xAxisTitle": "Condition",
    "yAxisTitle": "Value"
  },
  "facet": {},
  "order": {
    "time": ["Baseline", "Week 12"],
    "xLabels": ["Baseline", "Week 12"],
    "yLabels": ["6", "8", "10", null]
  },
  "layers": [
    {
      "color": "time",
      "fill": "white",
      "width": 0.5,
      "outliers": true,
      "outlier_gp": {
        "colour": {},
        "fill": {},
        "shape": {},
        "size": {},
        "stroke": 0.5,
        "alpha": {}
      },
      "whisker_gp": {
        "colour": {},
        "linetype": {},
        "linewidth": {}
      },
      "staple_gp": {
        "colour": {},
        "linetype": {},
        "linewidth": {}
      },
      "median_gp": {
        "colour": {},
        "linetype": {},
        "linewidth": {}
      },
      "box_gp": {
        "colour": {},
        "linetype": {},
        "linewidth": {}
      },
      "notch": false,
      "notchwidth": 0.5,
      "staplewidth": 0,
      "varwidth": false,
      "na.rm": false,
      "data": [
        ["Id", "id", "time", "value"],
        ["1", "P1", "Baseline", "10.7446965936086"],
        ["2", "P2", "Baseline", "6.56387398133318"],
        ["3", "P3", "Baseline", "7.16684898747745"],
        ["4", "P4", "Baseline", "7.50524845863584"],
        ["5", "P5", "Baseline", "6.83519199065662"],
        ["6", "P6", "Baseline", "6.86326406572627"],
        ["7", "P7", "Baseline", "8.89776720834866"],
        ["8", "P8", "Baseline", "7.85965372893542"],
        ["9", "P9", "Baseline", "8.18318915153868"],
        ["10", "P10", "Baseline", "10.6279737287953"],
        ["11", "P11", "Baseline", "8.42838347639483"],
        ["12", "P12", "Baseline", "11.2601021397569"],
        ["13", "P13", "Baseline", "10.7377423111875"],
        ["14", "P14", "Baseline", "8.38882464816622"],
        ["15", "P15", "Baseline", "10.2752804801719"],
        ["16", "P16", "Baseline", "8.56121661358604"],
        ["17", "P17", "Baseline", "6.92743913229747"],
        ["18", "P18", "Baseline", "7.63120604055537"],
        ["19", "P19", "Baseline", "7.99421309327892"],
        ["20", "P20", "Baseline", "9.18579697939993"],
        ["21", "P21", "Baseline", "9.00770043154889"],
        ["22", "P22", "Baseline", "8.8464101970866"],
        ["23", "P23", "Baseline", "9.56715766497403"],
        ["24", "P24", "Baseline", "6.33440454008858"],
        ["25", "P25", "Baseline", "9.52750023710628"],
        ["26", "P1", "Week 12", "6.81083744662969"],
        ["27", "P2", "Week 12", "7.69660139111791"],
        ["28", "P3", "Week 12", "7.80381646819178"],
        ["29", "P4", "Week 12", "6.98606692118486"],
        ["30", "P5", "Week 12", "7.0477154638883"],
        ["31", "P6", "Week 12", "6.13980761188402"],
        ["32", "P7", "Week 12", "6.40815806832089"],
        ["33", "P8", "Week 12", "7.18738368010787"],
        ["34", "P9", "Week 12", "6.83863303897584"],
        ["35", "P10", "Week 12", "5.57548534508707"],
        ["36", "P11", "Week 12", "6.18654612754614"],
        ["37", "P12", "Week 12", "8.12434035631655"],
        ["38", "P13", "Week 12", "5.90878327719184"],
        ["39", "P14", "Week 12", "7.19310048516094"],
        ["40", "P15", "Week 12", "7.43316919991118"],
        ["41", "P16", "Week 12", "9.14966047258566"],
        ["42", "P17", "Week 12", "6.57614286130307"],
        ["43", "P18", "Week 12", "7.38025963798868"],
        ["44", "P19", "Week 12", "6.23468359501349"],
        ["45", "P20", "Week 12", "6.89128388751875"],
        ["46", "P21", "Week 12", "6.6642697929628"],
        ["47", "P22", "Week 12", "7.68253972250201"],
        ["48", "P23", "Week 12", "7.01696066720233"],
        ["49", "P24", "Week 12", "6.22730279615318"],
        ["50", "P25", "Week 12", "6.60567272487921"]
      ],
      "shape": 19,
      "stat": "StatBoxplot",
      "geom": "GeomBoxplot"
    },
    {
      "group": "id",
      "color": "gray",
      "linewidth": 0.3,
      "linetype": "solid",
      "lineend": "butt",
      "linejoin": "round",
      "linemitre": 10,
      "na.rm": false,
      "data": {
        "x": [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2],
        "y": [10.7447, 6.8108, 10.628, 5.5755, 8.4284, 6.1865, 11.2601, 8.1243, 10.7377, 5.9088, 8.3888, 7.1931, 10.2753, 7.4332, 8.5612, 9.1497, 6.9274, 6.5761, 7.6312, 7.3803, 7.9942, 6.2347, 6.5639, 7.6966, 9.1858, 6.8913, 9.0077, 6.6643, 8.8464, 7.6825, 9.5672, 7.017, 6.3344, 6.2273, 9.5275, 6.6057, 7.1668, 7.8038, 7.5052, 6.9861, 6.8352, 7.0477, 6.8633, 6.1398, 8.8978, 6.4082, 7.8597, 7.1874, 8.1832, 6.8386],
        "label": [],
        "color": ["gray", "gray", "gray", "gray", "gray", "gray", "gray", "gray", "gray", "gray", "gray", "gray", "gray", "gray", "gray", "gray", "gray", "gray", "gray", "gray", "gray", "gray", "gray", "gray", "gray", "gray", "gray", "gray", "gray", "gray", "gray", "gray", "gray", "gray", "gray", "gray", "gray", "gray", "gray", "gray", "gray", "gray", "gray", "gray", "gray", "gray", "gray", "gray", "gray", "gray"],
        "fill": [],
        "size": [],
        "shape": [],
        "panel": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
      },
      "stat": "StatIdentity",
      "geom": "GeomLine"
    },
    {
      "color": "time",
      "size": 1.2,
      "na.rm": false,
      "data": {
        "x": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
        "y": [10.7447, 6.5639, 7.1668, 7.5052, 6.8352, 6.8633, 8.8978, 7.8597, 8.1832, 10.628, 8.4284, 11.2601, 10.7377, 8.3888, 10.2753, 8.5612, 6.9274, 7.6312, 7.9942, 9.1858, 9.0077, 8.8464, 9.5672, 6.3344, 9.5275, 6.8108, 7.6966, 7.8038, 6.9861, 7.0477, 6.1398, 6.4082, 7.1874, 6.8386, 5.5755, 6.1865, 8.1243, 5.9088, 7.1931, 7.4332, 9.1497, 6.5761, 7.3803, 6.2347, 6.8913, 6.6643, 7.6825, 7.017, 6.2273, 6.6057],
        "label": [],
        "color": ["#F8766D", "#F8766D", "#F8766D", "#F8766D", "#F8766D", "#F8766D", "#F8766D", "#F8766D", "#F8766D", "#F8766D", "#F8766D", "#F8766D", "#F8766D", "#F8766D", "#F8766D", "#F8766D", "#F8766D", "#F8766D", "#F8766D", "#F8766D", "#F8766D", "#F8766D", "#F8766D", "#F8766D", "#F8766D", "#00BFC4", "#00BFC4", "#00BFC4", "#00BFC4", "#00BFC4", "#00BFC4", "#00BFC4", "#00BFC4", "#00BFC4", "#00BFC4", "#00BFC4", "#00BFC4", "#00BFC4", "#00BFC4", "#00BFC4", "#00BFC4", "#00BFC4", "#00BFC4", "#00BFC4", "#00BFC4", "#00BFC4", "#00BFC4", "#00BFC4", "#00BFC4", "#00BFC4"],
        "fill": [null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null],
        "size": ["1.2", "1.2", "1.2", "1.2", "1.2", "1.2", "1.2", "1.2", "1.2", "1.2", "1.2", "1.2", "1.2", "1.2", "1.2", "1.2", "1.2", "1.2", "1.2", "1.2", "1.2", "1.2", "1.2", "1.2", "1.2", "1.2", "1.2", "1.2", "1.2", "1.2", "1.2", "1.2", "1.2", "1.2", "1.2", "1.2", "1.2", "1.2", "1.2", "1.2", "1.2", "1.2", "1.2", "1.2", "1.2", "1.2", "1.2", "1.2", "1.2", "1.2"],
        "shape": ["19", "19", "19", "19", "19", "19", "19", "19", "19", "19", "19", "19", "19", "19", "19", "19", "19", "19", "19", "19", "19", "19", "19", "19", "19", "19", "19", "19", "19", "19", "19", "19", "19", "19", "19", "19", "19", "19", "19", "19", "19", "19", "19", "19", "19", "19", "19", "19", "19", "19"],
        "panel": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
      },
      "shape": 19,
      "stat": "StatIdentity",
      "geom": "GeomPoint"
    },
    {
      "vjust": 0,
      "label.x.npc": "left",
      "label.y.npc": "top",
      "label.sep": ", ",
      "method": "t.test",
      "method.args": [],
      "paired": true,
      "symnum.args": [],
      "hide.ns": false,
      "na.rm": false,
      "color": "black",
      "data": {
        "x": 1,
        "y": 11.2601,
        "label": "T-test, p = 6.2e-05",
        "panel": 1,
        "color": "black"
      },
      "stat": "StatCompareMeans",
      "geom": "GeomText"
    }
  ],
  "geoms": ["GeomBoxplot", "GeomLine", "GeomPoint", "GeomText"],
  "meta": {
    "id": false,
    "time": true,
    "value": false
  },
  "isGGPlot": true,
  "config": [],
  "isR": true,
  "decompiled": "ggplot(dat, aes(x = time, y = value)) +\n  geom_boxplot(aes(colour = time), stat = 'boxplot', fill = 'white', width = 0.5, outliers = TRUE, outlier_gp = list(colour = NULL, fill = NULL, shape = NULL, size = NULL, stroke = 0.5,      alpha = NULL), whisker_gp = list(colour = NULL, linetype = NULL, linewidth = NULL), staple_gp = list(colour = NULL, linetype = NULL, linewidth = NULL), median_gp = list(colour = NULL, linetype = NULL, linewidth = NULL), box_gp = list(colour = NULL, linetype = NULL, linewidth = NULL), notch = FALSE, notchwidth = 0.5, staplewidth = 0, varwidth = FALSE) +\n  geom_line(aes(group = id), colour = 'gray', linewidth = 0.3, linetype = 'solid', lineend = 'butt', linejoin = 'round', linemitre = 10) +\n  geom_point(aes(colour = time), size = 1.2) +\n  geom_text(stat = 'compare_means', vjust = 0, label.x.npc = 'left', label.y.npc = 'top', label.sep = ', ', method = 't.test', method.args = list(), paired = TRUE, symnum.args = list(), hide.ns = FALSE) +\n  labs(y = 'Value', x = 'Condition') +\n  theme_*() +  # complete theme (58 elements); original theme_*()/element_*() calls are lost"
},"evals":[],"jsHooks":[]}</script>
</div>
</div>
<p>Each grey line is one subject moving from Baseline to Week 12, the boxes summarize each timepoint, and the paired t-test labels the comparison. It’s interactive — hover a line to follow a subject — and the figure is one portable spec you can reproduce from R, Python or JavaScript.</p>
</section>
<section id="why-paired-not-two-independent-boxes" class="level2">
<h2 class="anchored" data-anchor-id="why-paired-not-two-independent-boxes">Why paired, not two independent boxes</h2>
<p>A side-by-side boxplot hides <em>who</em> changed. The connecting lines make within-subject change visible: a treatment can lower the group median while a handful of subjects still rise — exactly the pattern you want to catch before drawing conclusions.</p>
</section>
<section id="next" class="level2">
<h2 class="anchored" data-anchor-id="next">Next</h2>
<ul>
<li><a href="../ggplot-direct/">Use ggplot2 &amp; ggpubr plots directly with canvasXpress</a></li>
<li><a href="../volcano-plots-in-r/">Interactive volcano plots in R</a></li>
<li>Gallery: <a href="https://canvasxpress.org/examples.html" class="uri">https://canvasxpress.org/examples.html</a></li>
</ul>


</section>

 ]]></description>
  <category>R</category>
  <category>canvasXpress</category>
  <category>ggpubr</category>
  <category>visualization</category>
  <guid>https://neuhausi.github.io/canvasxpress-blog/posts/r/paired-boxplots/</guid>
  <pubDate>Tue, 22 Sep 2026 04:00:00 GMT</pubDate>
  <media:content url="https://neuhausi.github.io/canvasxpress-blog/posts/r/paired-boxplots/thumbnail.png" medium="image" type="image/png" height="115" width="144"/>
</item>
<item>
  <title>Use your ggplot2 (and ggpubr) plots directly with canvasXpress</title>
  <dc:creator>Isaac Neuhaus</dc:creator>
  <link>https://neuhausi.github.io/canvasxpress-blog/posts/r/ggplot-direct/</link>
  <description><![CDATA[ 




<p>If you already build plots with <strong>ggplot2</strong> or <strong>ggpubr</strong>, you don’t need to learn a new plotting API to make them interactive. <a href="https://canvasxpress.org">canvasXpress</a> accepts a <strong>ggplot object directly</strong>: pass it to <code>canvasXpress()</code> and it renders an interactive, reproducible version of the same figure — you keep your existing code.</p>
<section id="install" class="level2">
<h2 class="anchored" data-anchor-id="install">Install</h2>
<div class="cell">
<div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">install.packages</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"canvasXpress"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ggpubr"</span>))</span></code></pre></div>
</div>
</section>
<section id="wrap-a-plot-you-already-have" class="level2">
<h2 class="anchored" data-anchor-id="wrap-a-plot-you-already-have">Wrap a plot you already have</h2>
<p>Here’s an ordinary <code>ggpubr</code> boxplot with <strong>pairwise comparisons</strong> (<code>geom_pwc</code>) — the significance brackets that show a test between each pair of groups. Build it exactly as you normally would:</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(ggplot2)</span>
<span id="cb2-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(ggpubr)</span>
<span id="cb2-3"></span>
<span id="cb2-4">g <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggboxplot</span>(iris, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Species"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Sepal.Width"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Species"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_pwc</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">method =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"t_test"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"p.format"</span>)</span></code></pre></div>
</div>
<p>Now make it interactive — <strong>one call, the same object</strong>:</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(canvasXpress)</span>
<span id="cb3-2"></span>
<span id="cb3-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">canvasXpress</span>(g)</span></code></pre></div>
<div class="cell-output-display">
<div id="htmlwidget-816c9b0e3a797dc49aae" style="width:100%;height:433px;" class="canvasXpress html-widget"></div>
<script type="application/json" data-for="htmlwidget-816c9b0e3a797dc49aae">{"x":{
  "renderTo": "canvas",
  "data": [
    ["Id", "Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width", "Species"],
    ["1", "5.1", "3.5", "1.4", "0.2", "setosa"],
    ["2", "4.9", "3", "1.4", "0.2", "setosa"],
    ["3", "4.7", "3.2", "1.3", "0.2", "setosa"],
    ["4", "4.6", "3.1", "1.5", "0.2", "setosa"],
    ["5", "5", "3.6", "1.4", "0.2", "setosa"],
    ["6", "5.4", "3.9", "1.7", "0.4", "setosa"],
    ["7", "4.6", "3.4", "1.4", "0.3", "setosa"],
    ["8", "5", "3.4", "1.5", "0.2", "setosa"],
    ["9", "4.4", "2.9", "1.4", "0.2", "setosa"],
    ["10", "4.9", "3.1", "1.5", "0.1", "setosa"],
    ["11", "5.4", "3.7", "1.5", "0.2", "setosa"],
    ["12", "4.8", "3.4", "1.6", "0.2", "setosa"],
    ["13", "4.8", "3", "1.4", "0.1", "setosa"],
    ["14", "4.3", "3", "1.1", "0.1", "setosa"],
    ["15", "5.8", "4", "1.2", "0.2", "setosa"],
    ["16", "5.7", "4.4", "1.5", "0.4", "setosa"],
    ["17", "5.4", "3.9", "1.3", "0.4", "setosa"],
    ["18", "5.1", "3.5", "1.4", "0.3", "setosa"],
    ["19", "5.7", "3.8", "1.7", "0.3", "setosa"],
    ["20", "5.1", "3.8", "1.5", "0.3", "setosa"],
    ["21", "5.4", "3.4", "1.7", "0.2", "setosa"],
    ["22", "5.1", "3.7", "1.5", "0.4", "setosa"],
    ["23", "4.6", "3.6", "1", "0.2", "setosa"],
    ["24", "5.1", "3.3", "1.7", "0.5", "setosa"],
    ["25", "4.8", "3.4", "1.9", "0.2", "setosa"],
    ["26", "5", "3", "1.6", "0.2", "setosa"],
    ["27", "5", "3.4", "1.6", "0.4", "setosa"],
    ["28", "5.2", "3.5", "1.5", "0.2", "setosa"],
    ["29", "5.2", "3.4", "1.4", "0.2", "setosa"],
    ["30", "4.7", "3.2", "1.6", "0.2", "setosa"],
    ["31", "4.8", "3.1", "1.6", "0.2", "setosa"],
    ["32", "5.4", "3.4", "1.5", "0.4", "setosa"],
    ["33", "5.2", "4.1", "1.5", "0.1", "setosa"],
    ["34", "5.5", "4.2", "1.4", "0.2", "setosa"],
    ["35", "4.9", "3.1", "1.5", "0.2", "setosa"],
    ["36", "5", "3.2", "1.2", "0.2", "setosa"],
    ["37", "5.5", "3.5", "1.3", "0.2", "setosa"],
    ["38", "4.9", "3.6", "1.4", "0.1", "setosa"],
    ["39", "4.4", "3", "1.3", "0.2", "setosa"],
    ["40", "5.1", "3.4", "1.5", "0.2", "setosa"],
    ["41", "5", "3.5", "1.3", "0.3", "setosa"],
    ["42", "4.5", "2.3", "1.3", "0.3", "setosa"],
    ["43", "4.4", "3.2", "1.3", "0.2", "setosa"],
    ["44", "5", "3.5", "1.6", "0.6", "setosa"],
    ["45", "5.1", "3.8", "1.9", "0.4", "setosa"],
    ["46", "4.8", "3", "1.4", "0.3", "setosa"],
    ["47", "5.1", "3.8", "1.6", "0.2", "setosa"],
    ["48", "4.6", "3.2", "1.4", "0.2", "setosa"],
    ["49", "5.3", "3.7", "1.5", "0.2", "setosa"],
    ["50", "5", "3.3", "1.4", "0.2", "setosa"],
    ["51", "7", "3.2", "4.7", "1.4", "versicolor"],
    ["52", "6.4", "3.2", "4.5", "1.5", "versicolor"],
    ["53", "6.9", "3.1", "4.9", "1.5", "versicolor"],
    ["54", "5.5", "2.3", "4", "1.3", "versicolor"],
    ["55", "6.5", "2.8", "4.6", "1.5", "versicolor"],
    ["56", "5.7", "2.8", "4.5", "1.3", "versicolor"],
    ["57", "6.3", "3.3", "4.7", "1.6", "versicolor"],
    ["58", "4.9", "2.4", "3.3", "1", "versicolor"],
    ["59", "6.6", "2.9", "4.6", "1.3", "versicolor"],
    ["60", "5.2", "2.7", "3.9", "1.4", "versicolor"],
    ["61", "5", "2", "3.5", "1", "versicolor"],
    ["62", "5.9", "3", "4.2", "1.5", "versicolor"],
    ["63", "6", "2.2", "4", "1", "versicolor"],
    ["64", "6.1", "2.9", "4.7", "1.4", "versicolor"],
    ["65", "5.6", "2.9", "3.6", "1.3", "versicolor"],
    ["66", "6.7", "3.1", "4.4", "1.4", "versicolor"],
    ["67", "5.6", "3", "4.5", "1.5", "versicolor"],
    ["68", "5.8", "2.7", "4.1", "1", "versicolor"],
    ["69", "6.2", "2.2", "4.5", "1.5", "versicolor"],
    ["70", "5.6", "2.5", "3.9", "1.1", "versicolor"],
    ["71", "5.9", "3.2", "4.8", "1.8", "versicolor"],
    ["72", "6.1", "2.8", "4", "1.3", "versicolor"],
    ["73", "6.3", "2.5", "4.9", "1.5", "versicolor"],
    ["74", "6.1", "2.8", "4.7", "1.2", "versicolor"],
    ["75", "6.4", "2.9", "4.3", "1.3", "versicolor"],
    ["76", "6.6", "3", "4.4", "1.4", "versicolor"],
    ["77", "6.8", "2.8", "4.8", "1.4", "versicolor"],
    ["78", "6.7", "3", "5", "1.7", "versicolor"],
    ["79", "6", "2.9", "4.5", "1.5", "versicolor"],
    ["80", "5.7", "2.6", "3.5", "1", "versicolor"],
    ["81", "5.5", "2.4", "3.8", "1.1", "versicolor"],
    ["82", "5.5", "2.4", "3.7", "1", "versicolor"],
    ["83", "5.8", "2.7", "3.9", "1.2", "versicolor"],
    ["84", "6", "2.7", "5.1", "1.6", "versicolor"],
    ["85", "5.4", "3", "4.5", "1.5", "versicolor"],
    ["86", "6", "3.4", "4.5", "1.6", "versicolor"],
    ["87", "6.7", "3.1", "4.7", "1.5", "versicolor"],
    ["88", "6.3", "2.3", "4.4", "1.3", "versicolor"],
    ["89", "5.6", "3", "4.1", "1.3", "versicolor"],
    ["90", "5.5", "2.5", "4", "1.3", "versicolor"],
    ["91", "5.5", "2.6", "4.4", "1.2", "versicolor"],
    ["92", "6.1", "3", "4.6", "1.4", "versicolor"],
    ["93", "5.8", "2.6", "4", "1.2", "versicolor"],
    ["94", "5", "2.3", "3.3", "1", "versicolor"],
    ["95", "5.6", "2.7", "4.2", "1.3", "versicolor"],
    ["96", "5.7", "3", "4.2", "1.2", "versicolor"],
    ["97", "5.7", "2.9", "4.2", "1.3", "versicolor"],
    ["98", "6.2", "2.9", "4.3", "1.3", "versicolor"],
    ["99", "5.1", "2.5", "3", "1.1", "versicolor"],
    ["100", "5.7", "2.8", "4.1", "1.3", "versicolor"],
    ["101", "6.3", "3.3", "6", "2.5", "virginica"],
    ["102", "5.8", "2.7", "5.1", "1.9", "virginica"],
    ["103", "7.1", "3", "5.9", "2.1", "virginica"],
    ["104", "6.3", "2.9", "5.6", "1.8", "virginica"],
    ["105", "6.5", "3", "5.8", "2.2", "virginica"],
    ["106", "7.6", "3", "6.6", "2.1", "virginica"],
    ["107", "4.9", "2.5", "4.5", "1.7", "virginica"],
    ["108", "7.3", "2.9", "6.3", "1.8", "virginica"],
    ["109", "6.7", "2.5", "5.8", "1.8", "virginica"],
    ["110", "7.2", "3.6", "6.1", "2.5", "virginica"],
    ["111", "6.5", "3.2", "5.1", "2", "virginica"],
    ["112", "6.4", "2.7", "5.3", "1.9", "virginica"],
    ["113", "6.8", "3", "5.5", "2.1", "virginica"],
    ["114", "5.7", "2.5", "5", "2", "virginica"],
    ["115", "5.8", "2.8", "5.1", "2.4", "virginica"],
    ["116", "6.4", "3.2", "5.3", "2.3", "virginica"],
    ["117", "6.5", "3", "5.5", "1.8", "virginica"],
    ["118", "7.7", "3.8", "6.7", "2.2", "virginica"],
    ["119", "7.7", "2.6", "6.9", "2.3", "virginica"],
    ["120", "6", "2.2", "5", "1.5", "virginica"],
    ["121", "6.9", "3.2", "5.7", "2.3", "virginica"],
    ["122", "5.6", "2.8", "4.9", "2", "virginica"],
    ["123", "7.7", "2.8", "6.7", "2", "virginica"],
    ["124", "6.3", "2.7", "4.9", "1.8", "virginica"],
    ["125", "6.7", "3.3", "5.7", "2.1", "virginica"],
    ["126", "7.2", "3.2", "6", "1.8", "virginica"],
    ["127", "6.2", "2.8", "4.8", "1.8", "virginica"],
    ["128", "6.1", "3", "4.9", "1.8", "virginica"],
    ["129", "6.4", "2.8", "5.6", "2.1", "virginica"],
    ["130", "7.2", "3", "5.8", "1.6", "virginica"],
    ["131", "7.4", "2.8", "6.1", "1.9", "virginica"],
    ["132", "7.9", "3.8", "6.4", "2", "virginica"],
    ["133", "6.4", "2.8", "5.6", "2.2", "virginica"],
    ["134", "6.3", "2.8", "5.1", "1.5", "virginica"],
    ["135", "6.1", "2.6", "5.6", "1.4", "virginica"],
    ["136", "7.7", "3", "6.1", "2.3", "virginica"],
    ["137", "6.3", "3.4", "5.6", "2.4", "virginica"],
    ["138", "6.4", "3.1", "5.5", "1.8", "virginica"],
    ["139", "6", "3", "4.8", "1.8", "virginica"],
    ["140", "6.9", "3.1", "5.4", "2.1", "virginica"],
    ["141", "6.7", "3.1", "5.6", "2.4", "virginica"],
    ["142", "6.9", "3.1", "5.1", "2.3", "virginica"],
    ["143", "5.8", "2.7", "5.1", "1.9", "virginica"],
    ["144", "6.8", "3.2", "5.9", "2.3", "virginica"],
    ["145", "6.7", "3.3", "5.7", "2.5", "virginica"],
    ["146", "6.7", "3", "5.2", "2.3", "virginica"],
    ["147", "6.3", "2.5", "5", "1.9", "virginica"],
    ["148", "6.5", "3", "5.2", "2", "virginica"],
    ["149", "6.2", "3.4", "5.4", "2.3", "virginica"],
    ["150", "5.9", "3", "5.1", "1.8", "virginica"]
  ],
  "aes": {
    "x": "Species",
    "y": "Sepal.Width"
  },
  "mappings": {
    "x": true,
    "y": false
  },
  "scales": {
    "colors": ["#F8766D", "#00BA38", "#619CFF"],
    "sizes": 6
  },
  "coords": [],
  "theme": {
    "axis.line.arrow": "FALSE",
    "axis.line.arrow.fill": "black",
    "axis.line.colour": "black",
    "axis.line.linewidth": "0.5",
    "axis.minor.ticks.length": "0.75",
    "axis.text.colour": "black",
    "axis.text.fontweight": null,
    "axis.text.fontwidth": null,
    "axis.text.italic": null,
    "axis.text.r.fontweight": null,
    "axis.text.r.fontwidth": null,
    "axis.text.r.hjust": "0.5",
    "axis.text.r.italic": null,
    "axis.text.r.margin": 2.4,
    "axis.text.x.fontweight": null,
    "axis.text.x.fontwidth": null,
    "axis.text.x.italic": null,
    "axis.text.x.margin": 2.4,
    "axis.text.x.vjust": "1",
    "axis.text.x.top.fontweight": null,
    "axis.text.x.top.fontwidth": null,
    "axis.text.x.top.italic": null,
    "axis.text.x.top.margin": 2.4,
    "axis.text.x.top.vjust": "0",
    "axis.text.y.fontweight": null,
    "axis.text.y.fontwidth": null,
    "axis.text.y.hjust": "1",
    "axis.text.y.italic": null,
    "axis.text.y.margin": 2.4,
    "axis.text.y.right.fontweight": null,
    "axis.text.y.right.fontwidth": null,
    "axis.text.y.right.hjust": "0",
    "axis.text.y.right.italic": null,
    "axis.text.y.right.margin": 2.4,
    "axis.ticks.arrow": "FALSE",
    "axis.ticks.arrow.fill": "black",
    "axis.ticks.colour": "black",
    "axis.ticks.length": "0.5",
    "axis.title.x.fontweight": null,
    "axis.title.x.fontwidth": null,
    "axis.title.x.italic": null,
    "axis.title.x.margin": 3,
    "axis.title.x.vjust": "1",
    "axis.title.x.top.fontweight": null,
    "axis.title.x.top.fontwidth": null,
    "axis.title.x.top.italic": null,
    "axis.title.x.top.margin": 3,
    "axis.title.x.top.vjust": "0",
    "axis.title.y.angle": "90",
    "axis.title.y.fontweight": null,
    "axis.title.y.fontwidth": null,
    "axis.title.y.italic": null,
    "axis.title.y.margin": 3,
    "axis.title.y.vjust": "1",
    "axis.title.y.right.angle": "-90",
    "axis.title.y.right.fontweight": null,
    "axis.title.y.right.fontwidth": null,
    "axis.title.y.right.italic": null,
    "axis.title.y.right.margin": 3,
    "axis.title.y.right.vjust": "1",
    "geom.accent": "#3366FF",
    "geom.bordertype": "1",
    "geom.borderwidth": "0.545454545454545",
    "geom.family": "",
    "geom.fontsize": "4.21751764217518",
    "geom.ink": "black",
    "geom.linetype": "1",
    "geom.linewidth": "0.545454545454545",
    "geom.paper": "white",
    "geom.pointshape": "19",
    "geom.pointsize": "1.63636363636364",
    "legend.background.colour": null,
    "legend.box.background": "element_blank",
    "legend.box.margin": "margin",
    "legend.box.spacing": "2",
    "legend.justification": "center",
    "legend.key": "element_blank",
    "legend.key.size": "1.2lines",
    "legend.position": "top",
    "legend.spacing": "2",
    "legend.text.fontweight": null,
    "legend.text.fontwidth": null,
    "legend.text.italic": null,
    "legend.text.size": 9,
    "legend.ticks.length": "0.2",
    "legend.title.fontweight": null,
    "legend.title.fontwidth": null,
    "legend.title.hjust": "0",
    "legend.title.italic": null,
    "line.arrow": "FALSE",
    "line.arrow.fill": "black",
    "line.colour": "black",
    "line.lineend": "butt",
    "line.linejoin": "round",
    "line.linetype": "1",
    "line.linewidth": "0.545454545454545",
    "margins": "margin",
    "panel.background.colour": null,
    "panel.background.fill": "white",
    "panel.border": "element_blank",
    "panel.grid.arrow": "FALSE",
    "panel.grid.arrow.fill": "#EBEBEBFF",
    "panel.grid.colour": "#EBEBEBFF",
    "panel.grid.major": "element_blank",
    "panel.grid.minor": "element_blank",
    "panel.ontop": "FALSE",
    "plot.background.colour": "white",
    "plot.caption.fontweight": null,
    "plot.caption.fontwidth": null,
    "plot.caption.hjust": "1",
    "plot.caption.italic": null,
    "plot.caption.margin": 6,
    "plot.caption.size": 9,
    "plot.caption.vjust": "1",
    "plot.caption.position": "panel",
    "plot.margin": "margin",
    "plot.subtitle.fontweight": null,
    "plot.subtitle.fontwidth": null,
    "plot.subtitle.hjust": "0",
    "plot.subtitle.italic": null,
    "plot.subtitle.margin": 6,
    "plot.subtitle.vjust": "1",
    "plot.tag.fontweight": null,
    "plot.tag.fontwidth": null,
    "plot.tag.hjust": "0.5",
    "plot.tag.italic": null,
    "plot.tag.size": 13,
    "plot.tag.vjust": "0.5",
    "plot.tag.position": "topleft",
    "plot.title.fontweight": null,
    "plot.title.fontwidth": null,
    "plot.title.hjust": "0",
    "plot.title.italic": null,
    "plot.title.margin": 6,
    "plot.title.size": 13,
    "plot.title.vjust": "1",
    "plot.title.position": "panel",
    "point.colour": "black",
    "point.fill": "white",
    "point.shape": "19",
    "point.size": "1.63636363636364",
    "point.stroke": "0.545454545454545",
    "polygon.colour": "black",
    "polygon.fill": "white",
    "polygon.linejoin": "round",
    "polygon.linetype": "1",
    "polygon.linewidth": "0.545454545454545",
    "rect.colour": "black",
    "rect.fill": "white",
    "rect.linejoin": "round",
    "rect.linetype": "1",
    "rect.linewidth": "0.545454545454545",
    "spacing": "6",
    "strip.background.colour": "black",
    "strip.background.fill": "#F2F2F2",
    "strip.background.linewidth": "0.7",
    "strip.clip": "on",
    "strip.placement": "inside",
    "strip.switch.pad.grid": "3",
    "strip.switch.pad.wrap": "3",
    "strip.text.colour": "#1A1A1AFF",
    "strip.text.fontweight": null,
    "strip.text.fontwidth": null,
    "strip.text.italic": null,
    "strip.text.margin": 4.8,
    "strip.text.size": 9,
    "strip.text.y.angle": "-90",
    "strip.text.y.fontweight": null,
    "strip.text.y.fontwidth": null,
    "strip.text.y.italic": null,
    "strip.text.y.left.angle": "90",
    "strip.text.y.left.fontweight": null,
    "strip.text.y.left.fontwidth": null,
    "strip.text.y.left.italic": null,
    "text.angle": "0",
    "text.colour": "black",
    "text.debug": "FALSE",
    "text.face": "plain",
    "text.family": "",
    "text.fontweight": null,
    "text.fontwidth": null,
    "text.hjust": "0.5",
    "text.italic": null,
    "text.lineheight": "0.9",
    "text.margin": 0,
    "text.size": "12",
    "text.vjust": "0.5",
    "title.fontweight": null,
    "title.fontwidth": null,
    "title.italic": null
  },
  "labels": [],
  "facet": {},
  "order": {
    "Species": ["setosa", "versicolor", "virginica"],
    "xLabels": ["setosa", "versicolor", "virginica"],
    "yLabels": ["2", "3", "4", "5"]
  },
  "layers": [
    {
      "fill": "Species",
      "color": "black",
      "linetype": "solid",
      "width": 0.7,
      "outliers": true,
      "outlier_gp": {
        "colour": {},
        "fill": {},
        "shape": 19,
        "size": {},
        "stroke": 0.5,
        "alpha": {}
      },
      "whisker_gp": {
        "colour": {},
        "linetype": {},
        "linewidth": {}
      },
      "staple_gp": {
        "colour": {},
        "linetype": {},
        "linewidth": {}
      },
      "median_gp": {
        "colour": {},
        "linetype": {},
        "linewidth": {}
      },
      "box_gp": {
        "colour": {},
        "linetype": {},
        "linewidth": {}
      },
      "notch": false,
      "notchwidth": 0.5,
      "staplewidth": 0,
      "varwidth": false,
      "na.rm": false,
      "position": "dodge",
      "data": [
        ["Id", "Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width", "Species"],
        ["1", "5.1", "3.5", "1.4", "0.2", "setosa"],
        ["2", "4.9", "3", "1.4", "0.2", "setosa"],
        ["3", "4.7", "3.2", "1.3", "0.2", "setosa"],
        ["4", "4.6", "3.1", "1.5", "0.2", "setosa"],
        ["5", "5", "3.6", "1.4", "0.2", "setosa"],
        ["6", "5.4", "3.9", "1.7", "0.4", "setosa"],
        ["7", "4.6", "3.4", "1.4", "0.3", "setosa"],
        ["8", "5", "3.4", "1.5", "0.2", "setosa"],
        ["9", "4.4", "2.9", "1.4", "0.2", "setosa"],
        ["10", "4.9", "3.1", "1.5", "0.1", "setosa"],
        ["11", "5.4", "3.7", "1.5", "0.2", "setosa"],
        ["12", "4.8", "3.4", "1.6", "0.2", "setosa"],
        ["13", "4.8", "3", "1.4", "0.1", "setosa"],
        ["14", "4.3", "3", "1.1", "0.1", "setosa"],
        ["15", "5.8", "4", "1.2", "0.2", "setosa"],
        ["16", "5.7", "4.4", "1.5", "0.4", "setosa"],
        ["17", "5.4", "3.9", "1.3", "0.4", "setosa"],
        ["18", "5.1", "3.5", "1.4", "0.3", "setosa"],
        ["19", "5.7", "3.8", "1.7", "0.3", "setosa"],
        ["20", "5.1", "3.8", "1.5", "0.3", "setosa"],
        ["21", "5.4", "3.4", "1.7", "0.2", "setosa"],
        ["22", "5.1", "3.7", "1.5", "0.4", "setosa"],
        ["23", "4.6", "3.6", "1", "0.2", "setosa"],
        ["24", "5.1", "3.3", "1.7", "0.5", "setosa"],
        ["25", "4.8", "3.4", "1.9", "0.2", "setosa"],
        ["26", "5", "3", "1.6", "0.2", "setosa"],
        ["27", "5", "3.4", "1.6", "0.4", "setosa"],
        ["28", "5.2", "3.5", "1.5", "0.2", "setosa"],
        ["29", "5.2", "3.4", "1.4", "0.2", "setosa"],
        ["30", "4.7", "3.2", "1.6", "0.2", "setosa"],
        ["31", "4.8", "3.1", "1.6", "0.2", "setosa"],
        ["32", "5.4", "3.4", "1.5", "0.4", "setosa"],
        ["33", "5.2", "4.1", "1.5", "0.1", "setosa"],
        ["34", "5.5", "4.2", "1.4", "0.2", "setosa"],
        ["35", "4.9", "3.1", "1.5", "0.2", "setosa"],
        ["36", "5", "3.2", "1.2", "0.2", "setosa"],
        ["37", "5.5", "3.5", "1.3", "0.2", "setosa"],
        ["38", "4.9", "3.6", "1.4", "0.1", "setosa"],
        ["39", "4.4", "3", "1.3", "0.2", "setosa"],
        ["40", "5.1", "3.4", "1.5", "0.2", "setosa"],
        ["41", "5", "3.5", "1.3", "0.3", "setosa"],
        ["42", "4.5", "2.3", "1.3", "0.3", "setosa"],
        ["43", "4.4", "3.2", "1.3", "0.2", "setosa"],
        ["44", "5", "3.5", "1.6", "0.6", "setosa"],
        ["45", "5.1", "3.8", "1.9", "0.4", "setosa"],
        ["46", "4.8", "3", "1.4", "0.3", "setosa"],
        ["47", "5.1", "3.8", "1.6", "0.2", "setosa"],
        ["48", "4.6", "3.2", "1.4", "0.2", "setosa"],
        ["49", "5.3", "3.7", "1.5", "0.2", "setosa"],
        ["50", "5", "3.3", "1.4", "0.2", "setosa"],
        ["51", "7", "3.2", "4.7", "1.4", "versicolor"],
        ["52", "6.4", "3.2", "4.5", "1.5", "versicolor"],
        ["53", "6.9", "3.1", "4.9", "1.5", "versicolor"],
        ["54", "5.5", "2.3", "4", "1.3", "versicolor"],
        ["55", "6.5", "2.8", "4.6", "1.5", "versicolor"],
        ["56", "5.7", "2.8", "4.5", "1.3", "versicolor"],
        ["57", "6.3", "3.3", "4.7", "1.6", "versicolor"],
        ["58", "4.9", "2.4", "3.3", "1", "versicolor"],
        ["59", "6.6", "2.9", "4.6", "1.3", "versicolor"],
        ["60", "5.2", "2.7", "3.9", "1.4", "versicolor"],
        ["61", "5", "2", "3.5", "1", "versicolor"],
        ["62", "5.9", "3", "4.2", "1.5", "versicolor"],
        ["63", "6", "2.2", "4", "1", "versicolor"],
        ["64", "6.1", "2.9", "4.7", "1.4", "versicolor"],
        ["65", "5.6", "2.9", "3.6", "1.3", "versicolor"],
        ["66", "6.7", "3.1", "4.4", "1.4", "versicolor"],
        ["67", "5.6", "3", "4.5", "1.5", "versicolor"],
        ["68", "5.8", "2.7", "4.1", "1", "versicolor"],
        ["69", "6.2", "2.2", "4.5", "1.5", "versicolor"],
        ["70", "5.6", "2.5", "3.9", "1.1", "versicolor"],
        ["71", "5.9", "3.2", "4.8", "1.8", "versicolor"],
        ["72", "6.1", "2.8", "4", "1.3", "versicolor"],
        ["73", "6.3", "2.5", "4.9", "1.5", "versicolor"],
        ["74", "6.1", "2.8", "4.7", "1.2", "versicolor"],
        ["75", "6.4", "2.9", "4.3", "1.3", "versicolor"],
        ["76", "6.6", "3", "4.4", "1.4", "versicolor"],
        ["77", "6.8", "2.8", "4.8", "1.4", "versicolor"],
        ["78", "6.7", "3", "5", "1.7", "versicolor"],
        ["79", "6", "2.9", "4.5", "1.5", "versicolor"],
        ["80", "5.7", "2.6", "3.5", "1", "versicolor"],
        ["81", "5.5", "2.4", "3.8", "1.1", "versicolor"],
        ["82", "5.5", "2.4", "3.7", "1", "versicolor"],
        ["83", "5.8", "2.7", "3.9", "1.2", "versicolor"],
        ["84", "6", "2.7", "5.1", "1.6", "versicolor"],
        ["85", "5.4", "3", "4.5", "1.5", "versicolor"],
        ["86", "6", "3.4", "4.5", "1.6", "versicolor"],
        ["87", "6.7", "3.1", "4.7", "1.5", "versicolor"],
        ["88", "6.3", "2.3", "4.4", "1.3", "versicolor"],
        ["89", "5.6", "3", "4.1", "1.3", "versicolor"],
        ["90", "5.5", "2.5", "4", "1.3", "versicolor"],
        ["91", "5.5", "2.6", "4.4", "1.2", "versicolor"],
        ["92", "6.1", "3", "4.6", "1.4", "versicolor"],
        ["93", "5.8", "2.6", "4", "1.2", "versicolor"],
        ["94", "5", "2.3", "3.3", "1", "versicolor"],
        ["95", "5.6", "2.7", "4.2", "1.3", "versicolor"],
        ["96", "5.7", "3", "4.2", "1.2", "versicolor"],
        ["97", "5.7", "2.9", "4.2", "1.3", "versicolor"],
        ["98", "6.2", "2.9", "4.3", "1.3", "versicolor"],
        ["99", "5.1", "2.5", "3", "1.1", "versicolor"],
        ["100", "5.7", "2.8", "4.1", "1.3", "versicolor"],
        ["101", "6.3", "3.3", "6", "2.5", "virginica"],
        ["102", "5.8", "2.7", "5.1", "1.9", "virginica"],
        ["103", "7.1", "3", "5.9", "2.1", "virginica"],
        ["104", "6.3", "2.9", "5.6", "1.8", "virginica"],
        ["105", "6.5", "3", "5.8", "2.2", "virginica"],
        ["106", "7.6", "3", "6.6", "2.1", "virginica"],
        ["107", "4.9", "2.5", "4.5", "1.7", "virginica"],
        ["108", "7.3", "2.9", "6.3", "1.8", "virginica"],
        ["109", "6.7", "2.5", "5.8", "1.8", "virginica"],
        ["110", "7.2", "3.6", "6.1", "2.5", "virginica"],
        ["111", "6.5", "3.2", "5.1", "2", "virginica"],
        ["112", "6.4", "2.7", "5.3", "1.9", "virginica"],
        ["113", "6.8", "3", "5.5", "2.1", "virginica"],
        ["114", "5.7", "2.5", "5", "2", "virginica"],
        ["115", "5.8", "2.8", "5.1", "2.4", "virginica"],
        ["116", "6.4", "3.2", "5.3", "2.3", "virginica"],
        ["117", "6.5", "3", "5.5", "1.8", "virginica"],
        ["118", "7.7", "3.8", "6.7", "2.2", "virginica"],
        ["119", "7.7", "2.6", "6.9", "2.3", "virginica"],
        ["120", "6", "2.2", "5", "1.5", "virginica"],
        ["121", "6.9", "3.2", "5.7", "2.3", "virginica"],
        ["122", "5.6", "2.8", "4.9", "2", "virginica"],
        ["123", "7.7", "2.8", "6.7", "2", "virginica"],
        ["124", "6.3", "2.7", "4.9", "1.8", "virginica"],
        ["125", "6.7", "3.3", "5.7", "2.1", "virginica"],
        ["126", "7.2", "3.2", "6", "1.8", "virginica"],
        ["127", "6.2", "2.8", "4.8", "1.8", "virginica"],
        ["128", "6.1", "3", "4.9", "1.8", "virginica"],
        ["129", "6.4", "2.8", "5.6", "2.1", "virginica"],
        ["130", "7.2", "3", "5.8", "1.6", "virginica"],
        ["131", "7.4", "2.8", "6.1", "1.9", "virginica"],
        ["132", "7.9", "3.8", "6.4", "2", "virginica"],
        ["133", "6.4", "2.8", "5.6", "2.2", "virginica"],
        ["134", "6.3", "2.8", "5.1", "1.5", "virginica"],
        ["135", "6.1", "2.6", "5.6", "1.4", "virginica"],
        ["136", "7.7", "3", "6.1", "2.3", "virginica"],
        ["137", "6.3", "3.4", "5.6", "2.4", "virginica"],
        ["138", "6.4", "3.1", "5.5", "1.8", "virginica"],
        ["139", "6", "3", "4.8", "1.8", "virginica"],
        ["140", "6.9", "3.1", "5.4", "2.1", "virginica"],
        ["141", "6.7", "3.1", "5.6", "2.4", "virginica"],
        ["142", "6.9", "3.1", "5.1", "2.3", "virginica"],
        ["143", "5.8", "2.7", "5.1", "1.9", "virginica"],
        ["144", "6.8", "3.2", "5.9", "2.3", "virginica"],
        ["145", "6.7", "3.3", "5.7", "2.5", "virginica"],
        ["146", "6.7", "3", "5.2", "2.3", "virginica"],
        ["147", "6.3", "2.5", "5", "1.9", "virginica"],
        ["148", "6.5", "3", "5.2", "2", "virginica"],
        ["149", "6.2", "3.4", "5.4", "2.3", "virginica"],
        ["150", "5.9", "3", "5.1", "1.8", "virginica"]
      ],
      "shape": 19,
      "stat": "StatBoxplot",
      "geom": "GeomBoxplot"
    },
    {
      "size": 0.3,
      "label.size": 3.88,
      "family": "",
      "hjust": 0.5,
      "vjust": 0,
      "remove.bracket": false,
      "parse": false,
      "method": "t_test",
      "method.args": [],
      "stat.label": "p.format",
      "group.by": "x.var",
      "dodge": 0.8,
      "bracket.nudge.y": 0.05,
      "bracket.shorten": 0,
      "bracket.group.by": "x.var",
      "step.increase": 0.12,
      "tip.length": 0.03,
      "na.rm": false,
      "p.adjust.method": "holm",
      "p.adjust.by": "group",
      "symnum.args": {
        "cutpoints": [0, 0.0001, 0.001, 0.01, 0.05, "Inf"],
        "symbols": ["****", "***", "**", "*", "ns"]
      },
      "hide.ns": false,
      "color": "black",
      "shape": 19,
      "x": [1, 1, 2, 1, 1, 2, 2, 3, 3],
      "y": [4.448, 4.736, 5.024, 4.52, 4.808, 5.096, 4.52, 4.808, 5.096],
      "xmin": [1, 1, 2, 1, 1, 2, 1, 1, 2],
      "xmax": [2, 3, 3, 2, 3, 3, 2, 3, 3],
      "col": ["black", "black", "black", "black", "black", "black", "black", "black", "black"],
      "label": ["<0.0001", "<0.0001", "0.0018", "<0.0001", "<0.0001", "0.0018", "<0.0001", "<0.0001", "0.0018"],
      "panel": ["1", "1", "1", "1", "1", "1", "1", "1", "1"],
      "stat": "StatPwc",
      "geom": "GeomPwc"
    }
  ],
  "geoms": ["GeomBoxplot", "GeomPwc"],
  "meta": {
    "Sepal.Length": false,
    "Sepal.Width": false,
    "Petal.Length": false,
    "Petal.Width": false,
    "Species": true
  },
  "isGGPlot": true,
  "config": [],
  "isR": true,
  "decompiled": "ggplot(dat, aes(x = Species, y = Sepal.Width)) +\n  geom_boxplot(aes(fill = Species), stat = 'boxplot', colour = 'black', linetype = 'solid', width = 0.7, outliers = TRUE, outlier_gp = list(colour = NULL, fill = NULL, shape = 19, size = NULL, stroke = 0.5,      alpha = NULL), whisker_gp = list(colour = NULL, linetype = NULL, linewidth = NULL), staple_gp = list(colour = NULL, linetype = NULL, linewidth = NULL), median_gp = list(colour = NULL, linetype = NULL, linewidth = NULL), box_gp = list(colour = NULL, linetype = NULL, linewidth = NULL), notch = FALSE, notchwidth = 0.5, staplewidth = 0, varwidth = FALSE, position = 'dodge') +\n  geom_pwc(stat = 'pwc', size = 0.3, label.size = 3.88, family = '', hjust = 0.5, vjust = 0, method = 't_test', method.args = list(), stat.label = 'p.format', group.by = 'x.var', dodge = 0.8, bracket.nudge.y = 0.05, bracket.shorten = 0, bracket.group.by = 'x.var', step.increase = 0.12, tip.length = 0.03, p.adjust.method = 'holm', p.adjust.by = 'group', symnum.args = list(cutpoints = c(0, 1e-04, 0.001, 0.01, 0.05, Inf), symbols = c('****',  '***', '**', '*', 'ns')), hide.ns = FALSE, remove.bracket = FALSE, parse = FALSE) +\n  theme_*() +  # complete theme (58 elements); original theme_*()/element_*() calls are lost"
},"evals":[],"jsHooks":[]}</script>
</div>
</div>
<p>That’s the whole idea: no re-specification. canvasXpress reads the ggplot object — its data, aesthetics, layers, scales and the <code>geom_pwc</code> brackets — and renders it. Hover the points, drag to zoom, or open the toolbar to filter and re-style, and the result serializes to one portable spec you can store and reproduce from R, Python or JavaScript.</p>
</section>
<section id="what-transfers" class="level2">
<h2 class="anchored" data-anchor-id="what-transfers">What transfers</h2>
<ul>
<li><strong>Geoms and layers</strong> — points, boxes, lines, and stats like <code>geom_pwc</code> / <code>stat_compare_means</code>.</li>
<li><strong>Aesthetic mappings</strong> — <code>x</code>, <code>y</code>, <code>fill</code>, <code>color</code>, grouping.</li>
<li><strong>Scales, labels and facets</strong> from the ggplot object.</li>
</ul>
</section>
<section id="when-to-reach-for-the-native-api-instead" class="level2">
<h2 class="anchored" data-anchor-id="when-to-reach-for-the-native-api-instead">When to reach for the native API instead</h2>
<p>Wrapping a ggplot is ideal for reusing plots you already have. When you’re building a figure fresh — or want fine control over CanvasXpress-specific features (clustering, dendrograms, interactive annotations) — call <code>canvasXpress()</code> on your data directly with a <code>graphType</code>. See the other posts for that style.</p>
</section>
<section id="next" class="level2">
<h2 class="anchored" data-anchor-id="next">Next</h2>
<ul>
<li><a href="../paired-boxplots/">Paired before/after boxplots in R</a></li>
<li><a href="../volcano-plots-in-r/">Interactive volcano plots in R</a></li>
<li>Gallery: <a href="https://canvasxpress.org/examples.html" class="uri">https://canvasxpress.org/examples.html</a></li>
</ul>


</section>

 ]]></description>
  <category>R</category>
  <category>canvasXpress</category>
  <category>ggplot2</category>
  <category>ggpubr</category>
  <category>visualization</category>
  <guid>https://neuhausi.github.io/canvasxpress-blog/posts/r/ggplot-direct/</guid>
  <pubDate>Mon, 21 Sep 2026 04:00:00 GMT</pubDate>
  <media:content url="https://neuhausi.github.io/canvasxpress-blog/posts/r/ggplot-direct/thumbnail.png" medium="image" type="image/png" height="115" width="144"/>
</item>
<item>
  <title>Clustered heatmaps in R with canvasXpress</title>
  <dc:creator>Isaac Neuhaus</dc:creator>
  <link>https://neuhausi.github.io/canvasxpress-blog/posts/r/clustered-heatmap-in-r/</link>
  <description><![CDATA[ 




<p>The clustered heatmap is the default way to look at an expression matrix: rows and columns reordered by similarity, dendrograms on the margins, and sample metadata alongside. In this post we build one in R with <a href="https://canvasxpress.org">canvasXpress</a> — clustering happens inside the render, so you pass a plain matrix and get an interactive, reproducible figure.</p>
<section id="an-expression-matrix-with-sample-metadata" class="level2">
<h2 class="anchored" data-anchor-id="an-expression-matrix-with-sample-metadata">An expression matrix with sample metadata</h2>
<p>Swap this simulated block for your own matrix (genes in rows, samples in columns) and a table of per-sample annotations — the output of any normalization/DE pipeline works.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(canvasXpress)</span>
<span id="cb1-2"></span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set.seed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb1-4">ng    <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">40</span>                       <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># genes (rows)</span></span>
<span id="cb1-5">ns    <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>                       <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># samples (columns)</span></span>
<span id="cb1-6">genes <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Gene"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq_len</span>(ng))</span>
<span id="cb1-7">samps <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"S"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq_len</span>(ns))</span>
<span id="cb1-8">cond  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Tumor"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Normal"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">each =</span> ns <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb1-9"></span>
<span id="cb1-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Two gene blocks, up in one condition each</span></span>
<span id="cb1-11">m <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matrix</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rnorm</span>(ng <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> ns), ng, ns, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dimnames =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(genes, samps))</span>
<span id="cb1-12">m[ <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>, cond <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Tumor"</span>]  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> m[ <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>, cond <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Tumor"</span>]  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span></span>
<span id="cb1-13">m[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">21</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">40</span>, cond <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Normal"</span>] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> m[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">21</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">40</span>, cond <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Normal"</span>] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span></span></code></pre></div>
</div>
<p>canvasXpress takes the matrix as <code>data</code> and a <strong>sample annotation</strong> table (rows = samples) that becomes an annotation track over the columns.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">smpAnnot <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Condition =</span> cond, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">row.names =</span> samps, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">check.names =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span></code></pre></div>
</div>
</section>
<section id="the-plot" class="level2">
<h2 class="anchored" data-anchor-id="the-plot">The plot</h2>
<p><code>samplesClustered</code> and <code>variablesClustered</code> turn on hierarchical clustering (with dendrograms) on columns and rows; <code>colorSpectrum</code> sets the diverging palette.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">canvasXpress</span>(</span>
<span id="cb3-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data     =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.data.frame</span>(m),</span>
<span id="cb3-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">smpAnnot =</span> smpAnnot,</span>
<span id="cb3-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">graphType =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Heatmap"</span>,</span>
<span id="cb3-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">samplesClustered  =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,</span>
<span id="cb3-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">variablesClustered =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,</span>
<span id="cb3-7">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colorSpectrum =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"navy"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"white"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"firebrick3"</span>),</span>
<span id="cb3-8">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">showSmpDendrogram =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,</span>
<span id="cb3-9">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">showVarDendrogram =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,</span>
<span id="cb3-10">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Clustered expression heatmap"</span>,</span>
<span id="cb3-11">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width  =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">650</span>,</span>
<span id="cb3-12">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">height =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">550</span></span>
<span id="cb3-13">)</span></code></pre></div>
<div class="cell-output-display">
<div id="htmlwidget-4a76076b1b1481d3deb3" style="width:100%;height:550px;" class="canvasXpress html-widget"></div>
<script type="application/json" data-for="htmlwidget-4a76076b1b1481d3deb3">{"x":{"data":{"y":{"vars":["Gene1","Gene2","Gene3","Gene4","Gene5","Gene6","Gene7","Gene8","Gene9","Gene10","Gene11","Gene12","Gene13","Gene14","Gene15","Gene16","Gene17","Gene18","Gene19","Gene20","Gene21","Gene22","Gene23","Gene24","Gene25","Gene26","Gene27","Gene28","Gene29","Gene30","Gene31","Gene32","Gene33","Gene34","Gene35","Gene36","Gene37","Gene38","Gene39","Gene40"],"smps":["S1","S2","S3","S4","S5","S6","S7","S8","S9","S10","S11","S12","S13","S14","S15","S16","S17","S18","S19","S20","S21","S22","S23","S24","S25","S26","S27","S28","S29","S30"],"data":[[1.374,1.835,1.431,1.494,2.425,2.409,2.707,2.398,3.308,-0.5923,3.074,1.566,1.643,1.263,0.7846,-0.3411,-2.433,1.078,0.4893,-0.01128,-1.087,2.006,-0.9406,0.7372,-0.7951,1.135,0.4705,0.7721,-0.09954,-0.7094],[2.184,1.747,1.865,3.343,1.761,3.689,3.034,1.592,3.497,3.314,3.896,3.773,0.8532,2.291,1.977,1.502,-0.3405,-1.199,-0.7789,0.6197,-1.826,-2.071,0.6347,2.321,-0.01996,1.112,0.2782,-0.1408,-0.4399,0.8714],[1.164,2.697,3.178,1.785,3.058,3.587,2.223,3.324,2.815,1.364,1.397,1.982,1.483,1.115,2.701,0.5283,0.713,0.2166,1.744,-1.281,0.9953,3.056,-0.06249,0.3489,-2.514,-0.8708,-0.9779,0.3931,-0.7185,0.1051],[3.595,2.557,0.4764,1.82,2.886,1.669,1.121,1.299,0.1302,1.57,1.609,2.853,1.638,2.208,1.413,0.5422,-0.659,0.1431,-0.07839,-0.1243,-0.01186,-0.2614,0.1828,-1.134,2.211,0.2107,-0.9266,0.2242,-0.5546,-0.1869],[2.33,1.311,2.594,1.9,1.381,-0.2852,3.163,1.419,2.482,1.831,1.584,2.205,4.351,1.952,1.393,-0.1367,-0.0364,-1.066,-0.9756,0.1757,-0.5996,-0.4544,1.104,0.4213,-1.489,0.0694,1.92,0.02354,1.245,-3.213],[1.18,1.293,2.333,2.713,4.206,4.498,-0.0001649,0.9989,2.456,2.612,1.624,-1.008,4.447,0.3155,3.097,-1.137,-1.593,-0.4286,0.07066,1.693,-0.1779,0.1576,1.752,-0.9246,-1.161,-1.663,0.8813,-0.623,-1.259,-1.276],[2.487,2.365,3.063,1.926,1.745,2.667,1.455,1.332,1.647,2.678,1.633,0.6339,1.833,1.856,1.752,-1.497,0.8478,-0.6562,-1.519,0.6421,-0.426,0.9334,-0.9538,-1.007,1.458,0.8108,0.7421,1.262,-0.2154,0.7629],[2.738,2.769,1.696,1.962,0.5755,2.541,1.744,2.945,2.17,2.568,1.704,1.576,0.9563,3.18,1.84,-0.2234,-1.85,0.9594,0.8638,1.282,0.9967,0.3028,1.644,-0.1895,-2.19,-1.912,0.1476,-0.4058,-2.472,-0.4068],[2.576,1.888,2.37,1.318,1.856,1.987,1.834,2.434,1.136,1.427,3.442,2.237,0.02707,2.681,1.374,2.002,-0.3237,1.556,0.5016,0.1405,0.7277,-1.956,-0.8667,0.9339,0.7391,-1.247,0.4854,0.6668,-0.6742,-1.208],[1.695,2.881,2.267,1.676,2.208,2.51,3.02,3.005,2.679,0.6367,1.302,-0.3427,2.515,2.143,2.9,0.2217,-0.2552,-1.041,-0.3548,-1.113,-1.727,0.3535,0.2664,0.3439,-0.344,0.9982,0.1519,0.1646,-0.5013,-0.4393],[3.512,2.398,1.457,2.06,4.308,1.836,2.136,1.61,1.673,1.611,1.612,2.962,0.9094,0.8077,1.006,0.1644,0.06092,0.9306,-0.4884,-0.3397,0.3534,0.4504,0.2224,0.814,0.4559,-0.5409,0.042,1.782,1.542,-0.3756],[2.39,1.388,3.208,1.411,2.106,2.421,2.407,2.376,0.4309,2.278,2.653,1.396,4.285,3.169,2.849,0.3326,-0.8235,-0.07545,0.9363,-1.665,0.7268,0.6596,-0.2769,0.9153,0.8781,-0.2164,0.2234,0.7112,-0.962,-0.5014],[1.379,2.341,3.16,2.531,2.457,1.6,1.93,2.244,1.633,1.177,3.125,1.247,1.114,2.079,2.806,-0.3852,1.83,-1.967,-1.062,0.9289,0.6683,-1.031,1.394,-0.1719,-0.9585,-1.622,-1.01,-0.3377,-0.8722,0.4966],[-0.2147,0.8706,2.7,0.4816,1.923,0.6298,1.752,0.5737,3.364,1.931,1.228,0.4444,2.111,1.548,1.532,-1.399,-1.43,-0.7559,-0.9838,1.417,-2.424,-2.371,-0.6589,-2.402,-0.7058,-1.451,2.401,-0.009149,-1.398,1.521],[3.125,3.433,3.587,2.307,1.666,2.988,2.696,3.778,1.666,0.8323,1.492,0.5461,5.81,3.642,2.848,2.676,0.2541,0.4611,0.4242,-0.06272,-0.2354,-0.3246,0.6605,0.7959,-2.997,0.3509,0.802,-0.1253,0.1798,0.9881],[1.955,3.98,2.558,0.4636,1.965,3.52,3.146,2.134,2.733,1.992,2.524,2.056,0.8911,1.23,2.987,-0.4237,-2.94,0.1451,-0.4513,-0.9809,1.98,-0.9443,-0.01326,2.169,-0.9611,-0.1745,-0.2512,-2.091,1.154,1.246],[1.984,1.633,0.7234,1.699,2.788,1.691,-0.4031,2.766,2.947,2.129,3.018,2.509,2.308,2.303,2.576,-0.2986,0.002416,-2.442,0.9251,1.087,0.7968,-0.7659,-0.9315,0.05838,0.3802,-0.5914,1.213,1.697,-1.199,-0.3299],[2.944,0.9559,1.427,1.472,4.075,0.7467,2.573,2.955,2.004,1.854,1.749,-0.09788,0.8931,3.282,4.025,-1.792,0.5097,0.5803,-0.1986,0.1393,-1.709,-0.9538,1.215,-1.355,0.5051,-1.334,-0.6273,1.064,-0.4257,0.8443],[2.821,2.57,0.7754,1.348,3.027,2.642,2.375,1.949,1.648,1.836,0.57,0.9956,2.348,2.602,0.03765,-0.248,-1.085,0.6551,1.195,-0.3863,-1.664,-0.398,-2.088,-0.3676,2.027,-1.097,1.711,-0.7666,1.366,-0.9811],[2.594,1.865,1.527,1.943,3.208,1.955,1.575,1.694,1.47,3.764,3.709,2.536,1.127,1.693,0.8351,-0.2473,0.7048,-0.3045,0.4955,1.124,0.4911,-0.3112,-0.5262,-0.9345,0.06463,2.036,-0.3944,0.382,-0.6843,-0.1392],[0.919,2.402,-0.6204,-1.914,-1.231,-1.733,0.951,0.8937,0.7396,0.7626,1.435,-0.453,0.0773,-0.4184,-1.377,1.744,2.331,1.292,-0.2452,1.24,1.826,2.796,0.4586,1.958,2.464,1.674,-0.3215,2.242,2.686,4.185],[0.7821,-0.03924,0.04212,1.177,0.9839,0.002132,-0.3892,-1.047,-1.063,1.111,-0.7104,2.165,-0.2969,0.3551,0.1677,0.2131,2.976,3.972,0.6646,3.149,2.961,2.986,2.194,2.676,2.075,2.774,3.364,0.8672,2.39,1.987],[0.07456,0.6897,-0.9109,-1.665,0.2199,-0.6303,-0.2843,1.971,0.2462,-0.9232,-0.06507,1.246,-1.183,0.5135,1.585,3.785,1.157,1.91,3.283,1.158,2.294,1.205,2.264,2.866,1.513,2.785,3.132,3.49,0.6946,1.695],[-1.989,0.028,0.158,-0.4635,-1.467,-0.341,0.8574,-0.3836,-0.2895,0.1643,-1.759,0.5955,0.01129,0.01861,1.678,3.764,1.029,1.986,2.691,2.391,2.081,1.691,0.8813,2.235,2.749,2.763,1.226,1.752,3.217,1.416],[0.6198,-0.7433,-0.6546,-1.116,0.521,-1.157,1.72,1.654,-2.265,1.155,0.5697,0.004884,0.9916,1.318,0.4883,2.69,0.2285,0.8765,1.033,2.891,2.184,2.361,2.651,1.066,2.464,2.295,0.5896,2.184,2.795,2.771],[-0.05613,0.1888,1.767,-0.7508,-0.1588,1.803,0.2701,1.512,-1.409,-0.05652,1.612,0.2794,1.594,-0.06583,0.8787,0.8993,1.678,0.6559,0.6542,0.6647,2.166,3.399,0.9671,2.813,2.129,0.7476,0.1655,2.405,1.512,4.106],[-0.1558,-1.805,0.7167,2.087,1.465,-0.3311,-0.4222,0.08297,0.916,-2.129,-1.637,-0.7059,-1.373,-0.7003,-0.1449,2.715,0.6612,0.4768,3.034,2.398,0.7304,1.944,2.659,3.348,1.185,0.9905,1.731,1.006,1.096,2.412],[-1.471,1.466,0.9102,0.0174,-0.7661,-1.606,-1.189,0.5672,-0.1913,0.3448,-0.7796,0.628,-0.2496,0.5373,0.469,1.754,2.688,1.578,1.188,1.888,4.349,0.3011,2.238,4.252,1.96,2.751,0.1661,0.9146,1.61,1.739],[-0.4782,0.1533,0.3842,-1.286,-0.4302,0.1972,-0.331,-1.025,0.8033,-1.905,-0.6412,1.48,1.159,-2.202,0.3762,1.68,2.071,3.361,3.802,2.676,0.588,2.232,2.715,1.506,2.781,0.6916,1.186,1.951,2.814,4.074],[0.4179,2.173,1.682,-1.641,-0.9261,0.2632,-0.9398,0.323,1.887,-0.8112,-0.6811,1.083,-1.114,0.392,-0.761,3.363,4.19,3.754,3.772,1.211,1.983,1.881,1.062,2.474,2.676,2.528,2.164,2.576,1.436,1.221],[1.359,0.4755,-0.6357,0.4502,-0.1771,-0.9858,-0.2589,1.044,1.474,1.324,-2.033,-0.8132,-2.529,0.497,-0.2933,0.7721,0.8423,3.568,0.5453,1.913,1.456,3.772,2.095,3.194,1.517,1.466,2.856,2.074,0.1258,3.132],[-0.1028,-0.7099,-0.4616,-0.01856,0.402,-2.889,0.3944,0.09908,0.6773,0.6156,0.501,-1.619,-0.9359,-0.2249,-0.1348,1.489,3.182,3.297,1.154,3.382,3.8,2.343,1.537,1.884,1.331,1.602,1.18,2.706,1.857,1.579],[0.3877,0.6107,1.432,-0.3181,-0.7317,-0.6405,-0.8519,-0.4541,0.38,1.092,-1.532,-0.1097,-0.9672,-1.117,1.394,1.269,1.473,1.762,0.7495,2.168,3.011,1.377,0.5311,2.525,2.513,1.21,1.876,2.335,2.772,0.9783],[-0.05381,-0.9341,-0.6507,-0.9294,0.8304,0.5705,2.649,-0.6558,-0.1928,0.3066,-0.025,0.4409,0.04749,-0.395,-1.037,2.02,0.5434,0.7758,2.667,2.823,1.436,1.56,2.153,2.214,3.049,1.77,2.255,2.545,0.8409,3.218],[-1.377,-1.254,-0.2074,-1.487,-1.208,-0.05972,0.156,-0.03592,1.578,-0.1102,0.593,1.351,-0.4037,1.55,-2.114,0.4271,2.573,1.672,0.7092,1.779,2.205,1.495,3.774,1.866,2.121,2.877,3.719,0.5971,1.762,0.2002],[-0.415,0.2914,-0.3928,-1.075,-1.048,-0.09818,1.13,1.069,0.5962,-0.9243,-0.1982,-1.319,0.2315,-0.7435,0.7683,1.297,0.5666,-0.4125,-0.035,0.9706,3.165,2.186,1.352,2.169,1.687,2.454,1.041,2.677,0.7778,1.692],[-0.3943,-0.4433,-0.32,1,1.441,0.5608,-2.289,-0.484,-1.174,1.593,0.892,0.3644,-0.4224,-2.332,-0.8162,2.716,0.9448,1.686,4.021,1.989,4.236,2.176,1.8,2.965,1.119,1.768,0.3957,1.21,2.117,2.016],[-0.05931,0.001105,-0.2791,-0.6213,-1.016,-1.186,0.741,-0.121,-0.1556,0.04501,-0.02572,0.2335,0.3741,0.8122,-0.4361,2.465,1.267,3.66,3.006,0.775,2.302,2.916,2.689,2.409,1.581,2.87,0.1544,1.534,1.868,1.558],[1.1,0.07434,0.4942,-1.384,0.412,1.097,-1.316,-1.294,-1.919,-0.7151,-0.6477,1.194,-0.366,-0.5013,0.9047,1.026,2.211,2.131,2.817,-0.5961,0.9575,2.32,2.036,1.534,0.5172,3.656,2.556,1.895,1.966,0.362],[0.7632,-0.5895,-0.1773,1.869,-0.3811,-0.005344,0.9198,0.4943,-0.1953,0.8652,0.6464,-0.02791,1.19,-0.5109,-0.7631,2.559,1.001,3.096,1.336,3.169,1.016,1.633,3.944,-0.2398,1.303,1.994,1.94,0.3521,1.378,1.359]]},"x":{"Condition":["Tumor","Tumor","Tumor","Tumor","Tumor","Tumor","Tumor","Tumor","Tumor","Tumor","Tumor","Tumor","Tumor","Tumor","Tumor","Normal","Normal","Normal","Normal","Normal","Normal","Normal","Normal","Normal","Normal","Normal","Normal","Normal","Normal","Normal"]},"z":null},"config":{"graphType":"Heatmap","isR":true,"samplesClustered":true,"variablesClustered":true,"colorSpectrum":["navy","white","firebrick3"],"showSmpDendrogram":true,"showVarDendrogram":true,"title":"Clustered expression heatmap"},"events":null,"afterRender":null},"evals":[],"jsHooks":[]}</script>
</div>
</div>
<p>The rows and columns are reordered by similarity, the dendrograms show the clustering, and the samples separate cleanly by condition. Hover a cell for its gene, sample and value; the whole figure is one portable spec you can store, validate and re-render.</p>
</section>
<section id="scaling-up" class="level2">
<h2 class="anchored" data-anchor-id="scaling-up">Scaling up</h2>
<p>The same call handles much larger matrices — hundreds of genes by dozens to hundreds of samples — clustering and rendering the full matrix interactively in the browser, not a static image. Point size and labels adapt automatically.</p>
</section>
<section id="next" class="level2">
<h2 class="anchored" data-anchor-id="next">Next</h2>
<ul>
<li><a href="../volcano-plots-in-r/">Interactive volcano plots in R</a></li>
<li><a href="../kaplan-meier-in-r/">Kaplan–Meier survival curves in R</a></li>
<li>Gallery: <a href="https://canvasxpress.org/examples.html" class="uri">https://canvasxpress.org/examples.html</a></li>
</ul>


</section>

 ]]></description>
  <category>R</category>
  <category>canvasXpress</category>
  <category>heatmap</category>
  <category>bioinformatics</category>
  <category>visualization</category>
  <guid>https://neuhausi.github.io/canvasxpress-blog/posts/r/clustered-heatmap-in-r/</guid>
  <pubDate>Sun, 20 Sep 2026 04:00:00 GMT</pubDate>
  <media:content url="https://neuhausi.github.io/canvasxpress-blog/posts/r/clustered-heatmap-in-r/thumbnail.png" medium="image" type="image/png" height="108" width="144"/>
</item>
<item>
  <title>Kaplan–Meier survival curves in R with canvasXpress</title>
  <dc:creator>Isaac Neuhaus</dc:creator>
  <link>https://neuhausi.github.io/canvasxpress-blog/posts/r/kaplan-meier-in-r/</link>
  <description><![CDATA[ 




<p>Kaplan–Meier curves summarize time-to-event data: the step-down survival probability over time, usually split by a group like treatment arm. In this post we build one in R with <a href="https://canvasxpress.org">canvasXpress</a>. canvasXpress computes the survival steps for you — you hand it a <strong>time</strong> column and a <strong>censoring</strong> column, and it does the rest — and the result is an interactive figure that serializes to one portable, reproducible spec.</p>
<section id="a-survival-table" class="level2">
<h2 class="anchored" data-anchor-id="a-survival-table">A survival table</h2>
<p>Swap this simulated block for your own data: you need, per subject, a follow-up <strong>time</strong>, a <strong>censoring indicator</strong> (1 = censored, 0 = event), and the grouping variable.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(canvasXpress)</span>
<span id="cb1-2"></span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set.seed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb1-4">n    <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span></span>
<span id="cb1-5">arm  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Treatment"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Control"</span>), n, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">replace =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb1-6">base <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(arm <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Treatment"</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">60</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">40</span>)      <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># treatment survives longer</span></span>
<span id="cb1-7">time <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rexp</span>(n, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rate =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> base), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb1-8">cens <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbinom</span>(n, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3</span>)                        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 1 = censored, 0 = event</span></span>
<span id="cb1-9">subj <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Subj"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq_len</span>(n))</span></code></pre></div>
</div>
<p>canvasXpress reads two columns for a Kaplan–Meier plot — the time and its matching censor flag — plus a per-subject annotation carrying the group.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">y <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(</span>
<span id="cb2-2">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Time"</span>        <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> time,</span>
<span id="cb2-3">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Time-Censor"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> cens,</span>
<span id="cb2-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">row.names     =</span> subj,</span>
<span id="cb2-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">check.names   =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span></span>
<span id="cb2-6">)</span>
<span id="cb2-7"></span>
<span id="cb2-8">varAnnot <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Arm =</span> arm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">row.names =</span> subj, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">check.names =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span></code></pre></div>
</div>
</section>
<section id="the-plot" class="level2">
<h2 class="anchored" data-anchor-id="the-plot">The plot</h2>
<p>The key is <code>graphType = "KaplanMeier"</code> and passing <strong>both</strong> columns to <code>xAxis</code> (time first, then the censor column). <code>colorBy</code> stratifies the curves.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">canvasXpress</span>(</span>
<span id="cb3-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data     =</span> y,</span>
<span id="cb3-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">varAnnot =</span> varAnnot,</span>
<span id="cb3-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">graphType =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"KaplanMeier"</span>,</span>
<span id="cb3-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xAxis    =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Time"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Time-Censor"</span>),</span>
<span id="cb3-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colorBy  =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Arm"</span>,</span>
<span id="cb3-7">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title    =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Overall survival by treatment arm"</span>,</span>
<span id="cb3-8">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xAxisTitle =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Time (weeks)"</span>,</span>
<span id="cb3-9">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yAxisTitle =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Probability of survival"</span>,</span>
<span id="cb3-10">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">invertCensored =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,     <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># draw censoring ticks</span></span>
<span id="cb3-11">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">showKMConfidenceIntervals =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>,</span>
<span id="cb3-12">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width  =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">650</span>,</span>
<span id="cb3-13">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">height =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500</span></span>
<span id="cb3-14">)</span></code></pre></div>
<div class="cell-output-display">
<div id="htmlwidget-b2f9e4180126f91fe927" style="width:100%;height:500px;" class="canvasXpress html-widget"></div>
<script type="application/json" data-for="htmlwidget-b2f9e4180126f91fe927">{"x":{"data":{"y":{"vars":["Subj1","Subj2","Subj3","Subj4","Subj5","Subj6","Subj7","Subj8","Subj9","Subj10","Subj11","Subj12","Subj13","Subj14","Subj15","Subj16","Subj17","Subj18","Subj19","Subj20","Subj21","Subj22","Subj23","Subj24","Subj25","Subj26","Subj27","Subj28","Subj29","Subj30","Subj31","Subj32","Subj33","Subj34","Subj35","Subj36","Subj37","Subj38","Subj39","Subj40","Subj41","Subj42","Subj43","Subj44","Subj45","Subj46","Subj47","Subj48","Subj49","Subj50","Subj51","Subj52","Subj53","Subj54","Subj55","Subj56","Subj57","Subj58","Subj59","Subj60","Subj61","Subj62","Subj63","Subj64","Subj65","Subj66","Subj67","Subj68","Subj69","Subj70","Subj71","Subj72","Subj73","Subj74","Subj75","Subj76","Subj77","Subj78","Subj79","Subj80","Subj81","Subj82","Subj83","Subj84","Subj85","Subj86","Subj87","Subj88","Subj89","Subj90","Subj91","Subj92","Subj93","Subj94","Subj95","Subj96","Subj97","Subj98","Subj99","Subj100","Subj101","Subj102","Subj103","Subj104","Subj105","Subj106","Subj107","Subj108","Subj109","Subj110","Subj111","Subj112","Subj113","Subj114","Subj115","Subj116","Subj117","Subj118","Subj119","Subj120","Subj121","Subj122","Subj123","Subj124","Subj125","Subj126","Subj127","Subj128","Subj129","Subj130","Subj131","Subj132","Subj133","Subj134","Subj135","Subj136","Subj137","Subj138","Subj139","Subj140","Subj141","Subj142","Subj143","Subj144","Subj145","Subj146","Subj147","Subj148","Subj149","Subj150","Subj151","Subj152","Subj153","Subj154","Subj155","Subj156","Subj157","Subj158","Subj159","Subj160","Subj161","Subj162","Subj163","Subj164","Subj165","Subj166","Subj167","Subj168","Subj169","Subj170","Subj171","Subj172","Subj173","Subj174","Subj175","Subj176","Subj177","Subj178","Subj179","Subj180","Subj181","Subj182","Subj183","Subj184","Subj185","Subj186","Subj187","Subj188","Subj189","Subj190","Subj191","Subj192","Subj193","Subj194","Subj195","Subj196","Subj197","Subj198","Subj199","Subj200"],"smps":["Time","Time-Censor"],"data":[[45.8,0],[62.9,1],[110.1,0],[2.2,0],[5,1],[85.2,1],[43.1,0],[26.2,0],[2.8,1],[8.5,1],[17.9,0],[14.1,0],[44.6,0],[102.6,1],[58.9,1],[0.8,0],[7.1,0],[130.4,0],[54.6,1],[5.5,1],[71.5,0],[15.8,0],[75.2,0],[22.8,0],[22.7,1],[6.6,0],[36.2,0],[9.4,0],[5.9,0],[82.9,1],[31.4,0],[21.1,0],[61.8,0],[90,1],[71.1,1],[13.2,0],[32.2,1],[34.5,0],[16.2,0],[68.3,0],[84.4,0],[20.4,0],[14.4,0],[69.7,1],[113.9,1],[77,0],[28.9,0],[73.4,1],[42.7,0],[3.3,1],[1.3,0],[89.7,0],[39.2,0],[65,0],[86.6,0],[88.6,1],[9.1,1],[106.6,0],[84.6,1],[20.8,1],[155.8,1],[38.1,0],[71.9,0],[25.1,1],[87,0],[51.8,1],[60.6,0],[116,0],[27.3,0],[17.6,1],[30.5,0],[30,0],[15,0],[19.8,0],[56.6,0],[52.6,1],[21.7,0],[45.9,0],[31.5,0],[8.1,0],[92.6,0],[45.9,0],[48.1,0],[7.3,0],[73.8,1],[14.1,1],[46.2,0],[32.5,0],[27,1],[29.5,0],[3.4,0],[4.5,0],[41.1,0],[27,0],[48,0],[10.4,1],[40.4,0],[88.7,1],[16.2,0],[23.9,1],[39.8,0],[6.1,0],[55,1],[61.6,0],[7.4,1],[65.1,0],[9.7,1],[26.5,0],[130.9,0],[92.1,0],[6.4,0],[65.2,0],[19.2,0],[37.6,1],[44,1],[62.8,0],[12.7,1],[112,0],[24.9,0],[17.9,0],[47,0],[22.5,1],[275.2,0],[14.9,0],[19.8,0],[35.1,1],[24.7,0],[36.3,1],[15.6,0],[38.7,0],[63,0],[91.9,0],[42.8,0],[79,0],[97.8,0],[34.9,1],[2,1],[3,0],[110.4,0],[36.2,0],[19.2,0],[206.5,0],[43.3,0],[34.8,0],[0.1,1],[8.8,0],[30,0],[55.4,1],[69.6,0],[2.9,0],[10.3,0],[104.9,1],[190.4,0],[2.7,1],[41.7,0],[29.5,1],[4.5,1],[40.5,1],[11,0],[89.8,0],[62.3,0],[31.2,0],[97.8,0],[16.3,1],[0.3,1],[114.3,1],[253.3,0],[235.3,0],[6.8,1],[51.6,0],[59.6,0],[41.5,0],[126.3,0],[19,0],[19.6,1],[38.9,0],[14.8,0],[0.2,1],[18.2,1],[26,0],[75.4,1],[17.5,0],[5,0],[62.1,0],[16.5,0],[39.5,1],[16.7,0],[65.2,1],[56.5,0],[74.7,1],[31.6,0],[16.8,0],[219.5,1],[84.4,0],[41.6,0],[71,0],[14.6,0],[51.4,0],[13.7,0],[117.8,0]]},"x":null,"z":{"Arm":["Treatment","Control","Treatment","Treatment","Control","Treatment","Treatment","Treatment","Control","Control","Treatment","Treatment","Treatment","Treatment","Treatment","Control","Control","Control","Control","Treatment","Treatment","Treatment","Treatment","Treatment","Treatment","Treatment","Control","Treatment","Treatment","Control","Control","Control","Treatment","Control","Treatment","Treatment","Control","Treatment","Control","Control","Control","Control","Treatment","Control","Control","Control","Control","Control","Treatment","Treatment","Control","Treatment","Control","Control","Treatment","Treatment","Control","Control","Control","Treatment","Treatment","Control","Control","Control","Control","Control","Control","Treatment","Control","Control","Control","Control","Treatment","Treatment","Treatment","Control","Control","Treatment","Treatment","Control","Control","Control","Treatment","Treatment","Treatment","Control","Treatment","Control","Treatment","Control","Treatment","Treatment","Control","Control","Treatment","Treatment","Treatment","Control","Control","Treatment","Control","Control","Control","Treatment","Treatment","Treatment","Treatment","Control","Treatment","Treatment","Treatment","Treatment","Treatment","Control","Control","Control","Control","Treatment","Control","Control","Control","Control","Treatment","Treatment","Control","Treatment","Treatment","Control","Control","Treatment","Treatment","Treatment","Control","Treatment","Control","Treatment","Control","Control","Control","Treatment","Control","Treatment","Treatment","Control","Treatment","Control","Control","Control","Treatment","Treatment","Control","Treatment","Treatment","Treatment","Treatment","Control","Control","Control","Control","Control","Treatment","Treatment","Treatment","Control","Treatment","Treatment","Control","Treatment","Treatment","Control","Treatment","Treatment","Control","Treatment","Treatment","Control","Control","Control","Control","Treatment","Control","Treatment","Treatment","Treatment","Treatment","Treatment","Control","Treatment","Control","Treatment","Treatment","Control","Treatment","Control","Control","Control","Treatment","Control","Treatment","Treatment"]}},"config":{"graphType":"KaplanMeier","isR":true,"xAxis":["Time","Time-Censor"],"colorBy":"Arm","title":"Overall survival by treatment arm","xAxisTitle":"Time (weeks)","yAxisTitle":"Probability of survival","invertCensored":true,"showKMConfidenceIntervals":false},"events":null,"afterRender":null},"evals":[],"jsHooks":[]}</script>
</div>
</div>
<p>Hover any step for the time and survival probability; the tick marks are censored subjects. Because canvasXpress derives the survival curve from the raw table, you never precompute the steps — and the same spec re-renders the identical curve from Python or JavaScript.</p>
</section>
<section id="a-common-gotcha" class="level2">
<h2 class="anchored" data-anchor-id="a-common-gotcha">A common gotcha</h2>
<p>The survival transform only fires with <code>graphType = "KaplanMeier"</code>. If you use a bare <code>"Scatter2D"</code> you’ll get a raw scatter of the censor values instead — survival probability is <em>computed</em> by the engine, it is not a column in your data.</p>
</section>
<section id="next" class="level2">
<h2 class="anchored" data-anchor-id="next">Next</h2>
<ul>
<li><a href="../volcano-plots-in-r/">Interactive volcano plots in R</a></li>
<li>Gallery: <a href="https://canvasxpress.org/examples.html" class="uri">https://canvasxpress.org/examples.html</a></li>
<li>Package &amp; issues: <a href="https://github.com/neuhausi/canvasXpress" class="uri">https://github.com/neuhausi/canvasXpress</a></li>
</ul>


</section>

 ]]></description>
  <category>R</category>
  <category>canvasXpress</category>
  <category>survival</category>
  <category>bioinformatics</category>
  <category>visualization</category>
  <guid>https://neuhausi.github.io/canvasxpress-blog/posts/r/kaplan-meier-in-r/</guid>
  <pubDate>Sat, 19 Sep 2026 04:00:00 GMT</pubDate>
  <media:content url="https://neuhausi.github.io/canvasxpress-blog/posts/r/kaplan-meier-in-r/thumbnail.png" medium="image" type="image/png" height="108" width="144"/>
</item>
<item>
  <title>Interactive volcano plots in R with canvasXpress</title>
  <dc:creator>Isaac Neuhaus</dc:creator>
  <link>https://neuhausi.github.io/canvasxpress-blog/posts/r/volcano-plots-in-r/</link>
  <description><![CDATA[ 




<p>A volcano plot is the workhorse of differential-expression analysis: log fold change on x, statistical significance on y, and the interesting genes pushed out to the top corners. In this post we build one in R with <a href="https://canvasxpress.org">canvasXpress</a> — interactive (zoom, hover, filter), and, importantly, <strong>reproducible</strong>: the whole figure is a single portable specification you can store, validate and re-render from R, Python or JavaScript.</p>
<section id="install" class="level2">
<h2 class="anchored" data-anchor-id="install">Install</h2>
<div class="cell">
<div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">install.packages</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"canvasXpress"</span>)</span></code></pre></div>
</div>
</section>
<section id="a-differential-expression-table" class="level2">
<h2 class="anchored" data-anchor-id="a-differential-expression-table">A differential-expression table</h2>
<p>For a self-contained example we simulate 1,000 genes. Swap this block for your own results table (e.g.&nbsp;the output of <code>limma::topTable()</code> or <code>DESeq2::results()</code>) — you need a log fold change and a significance value per gene.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(canvasXpress)</span>
<span id="cb2-2"></span>
<span id="cb2-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set.seed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb2-4">n     <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span></span>
<span id="cb2-5">genes <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Gene"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq_len</span>(n))</span>
<span id="cb2-6"></span>
<span id="cb2-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Simulate a realistic volcano: most genes have no real effect, a minority are</span></span>
<span id="cb2-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># differentially expressed. Significance follows effect size / standard error, which</span></span>
<span id="cb2-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># is what gives a volcano its shape.</span></span>
<span id="cb2-10">de     <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">runif</span>(n) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.12</span>                                   <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># ~12% truly changed</span></span>
<span id="cb2-11">sgn    <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>), n, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">replace =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb2-12">effect <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(de, sgn <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">runif</span>(n)), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)       <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># true log2FC</span></span>
<span id="cb2-13">se     <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.22</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">runif</span>(n)                             <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># per-gene standard error</span></span>
<span id="cb2-14">logFC  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(effect <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rnorm</span>(n, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, se), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)               <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># observed log2FC</span></span>
<span id="cb2-15">pval   <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pnorm</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(logFC <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> se))                       <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># z-test p-value</span></span>
<span id="cb2-16">negLogP <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pmin</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log10</span>(pval), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">16</span>), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span>
<span id="cb2-17"></span>
<span id="cb2-18"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Classify each gene by effect size + significance</span></span>
<span id="cb2-19">group <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(logFC <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span>  <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> negLogP <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.3</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Increased"</span>,</span>
<span id="cb2-20">         <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(logFC <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> negLogP <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.3</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Decreased"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"NoChange"</span>))</span></code></pre></div>
</div>
<p>canvasXpress expects a numeric matrix/data frame of values (genes in rows) plus an optional <strong>variable annotation</strong> table carrying per-gene attributes — here the regulation call and the fold change we’ll use for point size.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1">y <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(</span>
<span id="cb3-2">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"logFC"</span>     <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> logFC,</span>
<span id="cb3-3">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-log-pVal"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> negLogP,</span>
<span id="cb3-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">row.names   =</span> genes,</span>
<span id="cb3-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">check.names =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span></span>
<span id="cb3-6">)</span>
<span id="cb3-7"></span>
<span id="cb3-8">varAnnot <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(</span>
<span id="cb3-9">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Group =</span> group,</span>
<span id="cb3-10">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">FC    =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(logFC), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>),</span>
<span id="cb3-11">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">row.names   =</span> genes,</span>
<span id="cb3-12">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">check.names =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span></span>
<span id="cb3-13">)</span></code></pre></div>
</div>
</section>
<section id="the-plot" class="level2">
<h2 class="anchored" data-anchor-id="the-plot">The plot</h2>
<div class="cell">
<div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">canvasXpress</span>(</span>
<span id="cb4-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data     =</span> y,</span>
<span id="cb4-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">varAnnot =</span> varAnnot,</span>
<span id="cb4-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">graphType =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Scatter2D"</span>,</span>
<span id="cb4-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xAxis    =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"logFC"</span>),</span>
<span id="cb4-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yAxis    =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-log-pVal"</span>),</span>
<span id="cb4-7">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colorBy  =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Group"</span>,</span>
<span id="cb4-8">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colorKey =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Group =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(</span>
<span id="cb4-9">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Increased =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rgba(197,27,38,0.75)"</span>,</span>
<span id="cb4-10">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Decreased =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rgba(33,102,172,0.75)"</span>,</span>
<span id="cb4-11">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">NoChange  =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rgba(150,150,150,0.35)"</span></span>
<span id="cb4-12">  )),</span>
<span id="cb4-13">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sizeBy   =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"FC"</span>,</span>
<span id="cb4-14">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sizes    =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">15</span>),</span>
<span id="cb4-15">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title    =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Publication-ready volcano plot"</span>,</span>
<span id="cb4-16">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xAxisTitle =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"log2 fold change"</span>,</span>
<span id="cb4-17">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yAxisTitle =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-log10 p-value"</span>,</span>
<span id="cb4-18">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">showDecorations =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,</span>
<span id="cb4-19">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">decorations =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">line =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(</span>
<span id="cb4-20">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rgba(120,120,120,0.8)"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span>  <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>),</span>
<span id="cb4-21">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rgba(120,120,120,0.8)"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>),</span>
<span id="cb4-22">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rgba(120,120,120,0.8)"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.301</span>)</span>
<span id="cb4-23">  )),</span>
<span id="cb4-24">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width  =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">650</span>,</span>
<span id="cb4-25">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">height =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500</span></span>
<span id="cb4-26">)</span></code></pre></div>
<div class="cell-output-display">
<div id="htmlwidget-24b5851c0f08f8b8f4fa" style="width:100%;height:500px;" class="canvasXpress html-widget"></div>
<script type="application/json" data-for="htmlwidget-24b5851c0f08f8b8f4fa">{"x":{"data":{"y":{"vars":["Gene1","Gene2","Gene3","Gene4","Gene5","Gene6","Gene7","Gene8","Gene9","Gene10","Gene11","Gene12","Gene13","Gene14","Gene15","Gene16","Gene17","Gene18","Gene19","Gene20","Gene21","Gene22","Gene23","Gene24","Gene25","Gene26","Gene27","Gene28","Gene29","Gene30","Gene31","Gene32","Gene33","Gene34","Gene35","Gene36","Gene37","Gene38","Gene39","Gene40","Gene41","Gene42","Gene43","Gene44","Gene45","Gene46","Gene47","Gene48","Gene49","Gene50","Gene51","Gene52","Gene53","Gene54","Gene55","Gene56","Gene57","Gene58","Gene59","Gene60","Gene61","Gene62","Gene63","Gene64","Gene65","Gene66","Gene67","Gene68","Gene69","Gene70","Gene71","Gene72","Gene73","Gene74","Gene75","Gene76","Gene77","Gene78","Gene79","Gene80","Gene81","Gene82","Gene83","Gene84","Gene85","Gene86","Gene87","Gene88","Gene89","Gene90","Gene91","Gene92","Gene93","Gene94","Gene95","Gene96","Gene97","Gene98","Gene99","Gene100","Gene101","Gene102","Gene103","Gene104","Gene105","Gene106","Gene107","Gene108","Gene109","Gene110","Gene111","Gene112","Gene113","Gene114","Gene115","Gene116","Gene117","Gene118","Gene119","Gene120","Gene121","Gene122","Gene123","Gene124","Gene125","Gene126","Gene127","Gene128","Gene129","Gene130","Gene131","Gene132","Gene133","Gene134","Gene135","Gene136","Gene137","Gene138","Gene139","Gene140","Gene141","Gene142","Gene143","Gene144","Gene145","Gene146","Gene147","Gene148","Gene149","Gene150","Gene151","Gene152","Gene153","Gene154","Gene155","Gene156","Gene157","Gene158","Gene159","Gene160","Gene161","Gene162","Gene163","Gene164","Gene165","Gene166","Gene167","Gene168","Gene169","Gene170","Gene171","Gene172","Gene173","Gene174","Gene175","Gene176","Gene177","Gene178","Gene179","Gene180","Gene181","Gene182","Gene183","Gene184","Gene185","Gene186","Gene187","Gene188","Gene189","Gene190","Gene191","Gene192","Gene193","Gene194","Gene195","Gene196","Gene197","Gene198","Gene199","Gene200","Gene201","Gene202","Gene203","Gene204","Gene205","Gene206","Gene207","Gene208","Gene209","Gene210","Gene211","Gene212","Gene213","Gene214","Gene215","Gene216","Gene217","Gene218","Gene219","Gene220","Gene221","Gene222","Gene223","Gene224","Gene225","Gene226","Gene227","Gene228","Gene229","Gene230","Gene231","Gene232","Gene233","Gene234","Gene235","Gene236","Gene237","Gene238","Gene239","Gene240","Gene241","Gene242","Gene243","Gene244","Gene245","Gene246","Gene247","Gene248","Gene249","Gene250","Gene251","Gene252","Gene253","Gene254","Gene255","Gene256","Gene257","Gene258","Gene259","Gene260","Gene261","Gene262","Gene263","Gene264","Gene265","Gene266","Gene267","Gene268","Gene269","Gene270","Gene271","Gene272","Gene273","Gene274","Gene275","Gene276","Gene277","Gene278","Gene279","Gene280","Gene281","Gene282","Gene283","Gene284","Gene285","Gene286","Gene287","Gene288","Gene289","Gene290","Gene291","Gene292","Gene293","Gene294","Gene295","Gene296","Gene297","Gene298","Gene299","Gene300","Gene301","Gene302","Gene303","Gene304","Gene305","Gene306","Gene307","Gene308","Gene309","Gene310","Gene311","Gene312","Gene313","Gene314","Gene315","Gene316","Gene317","Gene318","Gene319","Gene320","Gene321","Gene322","Gene323","Gene324","Gene325","Gene326","Gene327","Gene328","Gene329","Gene330","Gene331","Gene332","Gene333","Gene334","Gene335","Gene336","Gene337","Gene338","Gene339","Gene340","Gene341","Gene342","Gene343","Gene344","Gene345","Gene346","Gene347","Gene348","Gene349","Gene350","Gene351","Gene352","Gene353","Gene354","Gene355","Gene356","Gene357","Gene358","Gene359","Gene360","Gene361","Gene362","Gene363","Gene364","Gene365","Gene366","Gene367","Gene368","Gene369","Gene370","Gene371","Gene372","Gene373","Gene374","Gene375","Gene376","Gene377","Gene378","Gene379","Gene380","Gene381","Gene382","Gene383","Gene384","Gene385","Gene386","Gene387","Gene388","Gene389","Gene390","Gene391","Gene392","Gene393","Gene394","Gene395","Gene396","Gene397","Gene398","Gene399","Gene400","Gene401","Gene402","Gene403","Gene404","Gene405","Gene406","Gene407","Gene408","Gene409","Gene410","Gene411","Gene412","Gene413","Gene414","Gene415","Gene416","Gene417","Gene418","Gene419","Gene420","Gene421","Gene422","Gene423","Gene424","Gene425","Gene426","Gene427","Gene428","Gene429","Gene430","Gene431","Gene432","Gene433","Gene434","Gene435","Gene436","Gene437","Gene438","Gene439","Gene440","Gene441","Gene442","Gene443","Gene444","Gene445","Gene446","Gene447","Gene448","Gene449","Gene450","Gene451","Gene452","Gene453","Gene454","Gene455","Gene456","Gene457","Gene458","Gene459","Gene460","Gene461","Gene462","Gene463","Gene464","Gene465","Gene466","Gene467","Gene468","Gene469","Gene470","Gene471","Gene472","Gene473","Gene474","Gene475","Gene476","Gene477","Gene478","Gene479","Gene480","Gene481","Gene482","Gene483","Gene484","Gene485","Gene486","Gene487","Gene488","Gene489","Gene490","Gene491","Gene492","Gene493","Gene494","Gene495","Gene496","Gene497","Gene498","Gene499","Gene500","Gene501","Gene502","Gene503","Gene504","Gene505","Gene506","Gene507","Gene508","Gene509","Gene510","Gene511","Gene512","Gene513","Gene514","Gene515","Gene516","Gene517","Gene518","Gene519","Gene520","Gene521","Gene522","Gene523","Gene524","Gene525","Gene526","Gene527","Gene528","Gene529","Gene530","Gene531","Gene532","Gene533","Gene534","Gene535","Gene536","Gene537","Gene538","Gene539","Gene540","Gene541","Gene542","Gene543","Gene544","Gene545","Gene546","Gene547","Gene548","Gene549","Gene550","Gene551","Gene552","Gene553","Gene554","Gene555","Gene556","Gene557","Gene558","Gene559","Gene560","Gene561","Gene562","Gene563","Gene564","Gene565","Gene566","Gene567","Gene568","Gene569","Gene570","Gene571","Gene572","Gene573","Gene574","Gene575","Gene576","Gene577","Gene578","Gene579","Gene580","Gene581","Gene582","Gene583","Gene584","Gene585","Gene586","Gene587","Gene588","Gene589","Gene590","Gene591","Gene592","Gene593","Gene594","Gene595","Gene596","Gene597","Gene598","Gene599","Gene600","Gene601","Gene602","Gene603","Gene604","Gene605","Gene606","Gene607","Gene608","Gene609","Gene610","Gene611","Gene612","Gene613","Gene614","Gene615","Gene616","Gene617","Gene618","Gene619","Gene620","Gene621","Gene622","Gene623","Gene624","Gene625","Gene626","Gene627","Gene628","Gene629","Gene630","Gene631","Gene632","Gene633","Gene634","Gene635","Gene636","Gene637","Gene638","Gene639","Gene640","Gene641","Gene642","Gene643","Gene644","Gene645","Gene646","Gene647","Gene648","Gene649","Gene650","Gene651","Gene652","Gene653","Gene654","Gene655","Gene656","Gene657","Gene658","Gene659","Gene660","Gene661","Gene662","Gene663","Gene664","Gene665","Gene666","Gene667","Gene668","Gene669","Gene670","Gene671","Gene672","Gene673","Gene674","Gene675","Gene676","Gene677","Gene678","Gene679","Gene680","Gene681","Gene682","Gene683","Gene684","Gene685","Gene686","Gene687","Gene688","Gene689","Gene690","Gene691","Gene692","Gene693","Gene694","Gene695","Gene696","Gene697","Gene698","Gene699","Gene700","Gene701","Gene702","Gene703","Gene704","Gene705","Gene706","Gene707","Gene708","Gene709","Gene710","Gene711","Gene712","Gene713","Gene714","Gene715","Gene716","Gene717","Gene718","Gene719","Gene720","Gene721","Gene722","Gene723","Gene724","Gene725","Gene726","Gene727","Gene728","Gene729","Gene730","Gene731","Gene732","Gene733","Gene734","Gene735","Gene736","Gene737","Gene738","Gene739","Gene740","Gene741","Gene742","Gene743","Gene744","Gene745","Gene746","Gene747","Gene748","Gene749","Gene750","Gene751","Gene752","Gene753","Gene754","Gene755","Gene756","Gene757","Gene758","Gene759","Gene760","Gene761","Gene762","Gene763","Gene764","Gene765","Gene766","Gene767","Gene768","Gene769","Gene770","Gene771","Gene772","Gene773","Gene774","Gene775","Gene776","Gene777","Gene778","Gene779","Gene780","Gene781","Gene782","Gene783","Gene784","Gene785","Gene786","Gene787","Gene788","Gene789","Gene790","Gene791","Gene792","Gene793","Gene794","Gene795","Gene796","Gene797","Gene798","Gene799","Gene800","Gene801","Gene802","Gene803","Gene804","Gene805","Gene806","Gene807","Gene808","Gene809","Gene810","Gene811","Gene812","Gene813","Gene814","Gene815","Gene816","Gene817","Gene818","Gene819","Gene820","Gene821","Gene822","Gene823","Gene824","Gene825","Gene826","Gene827","Gene828","Gene829","Gene830","Gene831","Gene832","Gene833","Gene834","Gene835","Gene836","Gene837","Gene838","Gene839","Gene840","Gene841","Gene842","Gene843","Gene844","Gene845","Gene846","Gene847","Gene848","Gene849","Gene850","Gene851","Gene852","Gene853","Gene854","Gene855","Gene856","Gene857","Gene858","Gene859","Gene860","Gene861","Gene862","Gene863","Gene864","Gene865","Gene866","Gene867","Gene868","Gene869","Gene870","Gene871","Gene872","Gene873","Gene874","Gene875","Gene876","Gene877","Gene878","Gene879","Gene880","Gene881","Gene882","Gene883","Gene884","Gene885","Gene886","Gene887","Gene888","Gene889","Gene890","Gene891","Gene892","Gene893","Gene894","Gene895","Gene896","Gene897","Gene898","Gene899","Gene900","Gene901","Gene902","Gene903","Gene904","Gene905","Gene906","Gene907","Gene908","Gene909","Gene910","Gene911","Gene912","Gene913","Gene914","Gene915","Gene916","Gene917","Gene918","Gene919","Gene920","Gene921","Gene922","Gene923","Gene924","Gene925","Gene926","Gene927","Gene928","Gene929","Gene930","Gene931","Gene932","Gene933","Gene934","Gene935","Gene936","Gene937","Gene938","Gene939","Gene940","Gene941","Gene942","Gene943","Gene944","Gene945","Gene946","Gene947","Gene948","Gene949","Gene950","Gene951","Gene952","Gene953","Gene954","Gene955","Gene956","Gene957","Gene958","Gene959","Gene960","Gene961","Gene962","Gene963","Gene964","Gene965","Gene966","Gene967","Gene968","Gene969","Gene970","Gene971","Gene972","Gene973","Gene974","Gene975","Gene976","Gene977","Gene978","Gene979","Gene980","Gene981","Gene982","Gene983","Gene984","Gene985","Gene986","Gene987","Gene988","Gene989","Gene990","Gene991","Gene992","Gene993","Gene994","Gene995","Gene996","Gene997","Gene998","Gene999","Gene1000"],"smps":["logFC","-log-pVal"],"data":[[-0.55,0.425],[-0.884,1.264],[0.5,0.978],[0.217,0.219],[-0.035,0.02],[0.481,0.313],[0.016,0.018],[-0.521,0.721],[-1.215,1.471],[1.079,0.91],[-0.136,0.123],[-0.305,0.538],[0.262,0.17],[-0.197,0.124],[0.556,0.388],[0.738,0.706],[-0.281,0.274],[-0.228,0.418],[0.084,0.053],[0.978,0.812],[-0.413,1.083],[-0.229,0.395],[-0.299,0.324],[0.111,0.15],[0.659,1.765],[-0.168,0.191],[0.648,0.69],[-0.495,1.052],[-0.487,0.527],[0.308,0.355],[-0.316,0.341],[-0.175,0.202],[-0.153,0.14],[-0.028,0.022],[1.028,0.978],[0.498,0.672],[0.883,1.352],[0.982,4.948],[-0.326,0.192],[0.406,0.528],[-0.071,0.118],[0.127,0.125],[-0.35,0.287],[-0.679,1.21],[-0.859,0.644],[0.495,1.236],[1.425,6.281],[0.629,1.132],[0.283,0.413],[0.487,0.317],[0.638,0.982],[-0.672,0.951],[-0.298,0.266],[-0.112,0.122],[1.107,2.053],[-1.448,3.027],[-0.794,1.43],[-0.314,0.805],[0.432,0.267],[0.067,0.092],[0.645,0.717],[-0.22,0.132],[-0.25,0.154],[-0.221,0.171],[-0.212,0.473],[0.095,0.095],[-0.772,0.622],[0.235,0.208],[-1.648,1.845],[0.553,0.358],[0.471,0.674],[-0.094,0.169],[-0.183,0.176],[-0.028,0.016],[-0.458,0.292],[0.935,0.963],[-0.03,0.022],[0.51,0.415],[0.244,0.152],[0.891,0.805],[-0.121,0.078],[-1.18,2.13],[0.267,0.265],[-0.659,0.521],[0.205,0.208],[-0.543,0.482],[-0.024,0.033],[-0.351,0.236],[-0.056,0.094],[-0.181,0.29],[-0.458,0.488],[1.496,2.113],[-0.636,0.65],[-0.191,0.111],[-0.112,0.117],[-0.314,0.282],[1.025,1.09],[-0.557,1.21],[0.018,0.011],[-0.798,0.644],[-0.541,0.745],[-0.011,0.016],[1.05,1.543],[0.393,0.81],[0.123,0.068],[-0.215,0.288],[1.086,1.386],[-0.094,0.089],[-0.548,0.429],[-0.946,0.758],[-0.329,0.252],[0.376,1.02],[0.759,0.557],[0.262,0.239],[-0.803,0.993],[0.895,3.466],[0.328,0.56],[1.366,1.646],[-0.26,0.305],[0.028,0.019],[-0.367,0.321],[-0.087,0.142],[0.999,1.781],[0.207,0.235],[0.545,0.674],[0.02,0.018],[-0.27,0.188],[0.458,0.292],[-0.489,0.861],[0.931,0.849],[-0.052,0.084],[-0.6,0.412],[-1.771,1.903],[-0.259,0.168],[1.102,1.33],[-0.029,0.028],[-0.959,0.86],[-0.184,0.111],[-0.368,0.434],[-1.029,0.937],[-0.327,0.298],[-0.944,1.197],[0.611,2.135],[0.188,0.107],[0.337,0.274],[-0.572,0.602],[0.726,0.71],[0.36,0.221],[1.369,4.965],[-0.048,0.039],[-0.148,0.162],[0.574,0.703],[-0.111,0.061],[0.659,0.557],[0.409,0.332],[-0.16,0.116],[-0.021,0.018],[0.981,4.139],[-0.27,0.209],[-0.461,0.79],[-0.112,0.173],[-0.104,0.145],[-0.144,0.082],[1.365,1.906],[0.034,0.053],[-0.422,0.856],[-1.052,3.366],[-0.132,0.112],[0.839,0.799],[0.034,0.019],[1.057,0.966],[-0.004,0.006],[-0.131,0.232],[0.644,1.319],[-0.797,0.765],[0.262,0.173],[-0.524,0.483],[0.352,0.633],[0.204,0.181],[-0.255,0.175],[-0.133,0.151],[0.533,0.427],[-0.339,0.543],[-0.318,0.36],[0.204,0.165],[0.335,0.344],[-1.137,1.064],[0.099,0.072],[-0.295,0.61],[-0.183,0.283],[0.385,0.723],[0.651,0.499],[1.525,1.551],[-0.624,0.455],[0.086,0.121],[0.976,0.945],[1.201,7.191],[0.228,0.162],[0.036,0.027],[0.376,0.539],[0.493,0.445],[0.582,0.379],[-0.336,0.321],[-1.847,2.146],[-0.179,0.244],[0.601,0.713],[-0.102,0.071],[-0.205,0.281],[-0.885,1.379],[-0.336,0.263],[-0.51,0.378],[1.278,2.862],[0.046,0.031],[-0.092,0.089],[0.755,0.685],[-0.786,0.928],[-0.797,0.868],[-0.457,0.565],[-0.016,0.01],[1.221,1.528],[0.833,0.768],[-0.228,0.151],[-0.176,0.361],[0.424,0.686],[0.175,0.12],[-0.281,0.17],[-0.01,0.013],[-0.384,0.313],[-0.057,0.038],[0.139,0.076],[0.525,0.361],[-0.127,0.231],[-0.777,1.369],[-0.014,0.007],[0.397,0.655],[-0.081,0.065],[0.301,0.296],[-0.266,0.233],[-0.635,0.445],[0.213,0.179],[-0.189,0.155],[0.454,0.398],[0.476,0.468],[-0.103,0.167],[0.037,0.036],[0.425,0.447],[0.539,0.84],[-0.193,0.16],[-0.214,0.202],[-0.195,0.124],[0.3,0.645],[-0.303,0.345],[-0.432,0.287],[-0.122,0.097],[-0.524,0.71],[-1.009,1.73],[-0.092,0.161],[0.031,0.021],[0.318,0.305],[0.426,0.933],[0.343,0.38],[-0.313,0.691],[0.359,0.88],[0.271,0.377],[0.046,0.023],[0.327,0.748],[-0.718,1.919],[-0.105,0.056],[-0.154,0.252],[0.613,0.426],[0.356,0.282],[-1.47,10.46],[-0.727,0.586],[-0.965,1.362],[0.096,0.084],[-0.083,0.047],[-1.042,1.366],[-0.07,0.107],[0.121,0.171],[0.274,0.284],[1.665,2.058],[0.297,0.325],[0.102,0.072],[0.192,0.147],[-0.942,1.263],[-0.531,0.523],[0.153,0.096],[0.525,0.448],[1.457,1.64],[-0.313,0.181],[0.004,0.004],[-1.38,1.477],[-0.445,0.368],[0.477,0.705],[-0.076,0.097],[0.343,0.244],[1.989,2.275],[-1.813,2.283],[-1.049,1.221],[0.146,0.089],[-0.144,0.122],[1.657,3.632],[-0.246,0.29],[-0.266,0.605],[0.225,0.224],[0.99,0.787],[0.052,0.067],[-0.041,0.025],[1.023,1.468],[0.991,0.803],[0.638,0.566],[0.948,0.795],[0.232,0.273],[0.146,0.105],[0.162,0.21],[0.17,0.101],[0.943,3.903],[1.295,1.504],[-0.662,0.599],[0.575,0.467],[-0.662,0.665],[-0.562,0.431],[-0.304,0.321],[-0.825,0.636],[-0.026,0.025],[-0.235,0.402],[0.082,0.058],[0.469,1.358],[0.193,0.336],[-0.654,1.042],[0.122,0.199],[0.043,0.027],[0.499,1.282],[0.193,0.212],[1.005,1.925],[-0.523,0.685],[0.029,0.017],[0.621,0.63],[-0.538,0.431],[-0.259,0.353],[0.357,0.488],[0.347,0.444],[-0.197,0.112],[-0.217,0.203],[-0.077,0.105],[0.323,0.571],[0.022,0.021],[0.183,0.099],[0.548,0.988],[0.208,0.415],[0.611,0.651],[-0.465,0.337],[-0.075,0.122],[-0.024,0.037],[0.111,0.062],[0.122,0.188],[-0.333,0.211],[-1.5,1.638],[-0.452,0.32],[0.176,0.14],[-2.117,5.514],[-0.14,0.088],[0.916,0.785],[-0.197,0.137],[-0.393,0.314],[0.315,0.253],[-2.955,5.477],[0.041,0.037],[0.104,0.077],[1.254,1.719],[-0.296,0.241],[-0.191,0.374],[0.523,1.654],[0.093,0.146],[-0.002,0.002],[0.145,0.215],[-0.287,0.184],[-0.619,0.646],[0.378,0.356],[0.045,0.032],[-0.027,0.035],[-0.621,0.726],[-0.242,0.37],[0.186,0.201],[-0.347,0.467],[0.328,0.21],[0.884,0.669],[0.421,0.463],[-1.41,2.932],[0.047,0.046],[0.003,0.003],[0.558,0.437],[0.088,0.154],[-0.31,0.718],[-0.079,0.133],[0.568,0.585],[0.621,0.456],[0.911,1.174],[-0.313,0.487],[-0.413,0.299],[-0.26,0.15],[0.254,0.494],[0.041,0.036],[0.823,0.86],[0.126,0.24],[0.085,0.052],[1.304,1.171],[0.185,0.219],[-1.281,5.007],[0.02,0.01],[-0.062,0.061],[-0.364,0.327],[-0.627,0.699],[-0.156,0.084],[0.012,0.009],[0.748,1.17],[0.297,0.622],[-0.198,0.142],[0.236,0.455],[-0.348,0.555],[0.081,0.043],[0.329,0.195],[-0.577,1.049],[0.505,0.633],[-0.425,0.308],[-1.195,1.153],[-1.998,2.376],[-1.052,1.313],[-0.136,0.168],[0.399,0.389],[-0.191,0.241],[0.561,0.38],[-0.077,0.131],[0.003,0.002],[1.321,1.213],[0.122,0.183],[-0.081,0.093],[1.266,4.805],[0.445,0.582],[0.611,0.943],[0.854,2.931],[0.347,0.206],[0.011,0.006],[0.31,0.728],[0.645,0.453],[0.49,0.549],[-0.155,0.117],[0.746,0.529],[0.278,0.32],[-1.615,2.472],[-0.227,0.454],[0.907,0.77],[-0.316,0.19],[0.918,0.726],[1.625,2.184],[-0.679,0.546],[-0.249,0.229],[-0.756,0.711],[0.126,0.071],[-1.921,13.69],[0.813,0.646],[0.068,0.113],[1.802,5.649],[-0.063,0.084],[0.395,0.821],[0.09,0.07],[-0.624,0.486],[-0.035,0.028],[0.539,0.435],[-0.969,0.83],[-0.027,0.026],[-0.397,0.371],[-1.112,0.913],[0.673,1.443],[-1.379,9.227],[0.191,0.216],[0.059,0.046],[-0.37,0.943],[0.048,0.026],[0.926,0.75],[0.943,0.772],[-0.126,0.219],[0.967,0.888],[0.956,0.873],[0.407,0.382],[1.1,1.018],[0.622,0.509],[-0.968,0.824],[-1.12,1.286],[0.349,0.308],[-1.086,1.712],[-0.27,0.396],[-0.047,0.055],[-0.637,0.496],[0.808,0.65],[-0.087,0.064],[-0.535,0.739],[0.048,0.052],[-0.532,0.706],[-1.763,3.304],[-0.939,1.149],[-0.419,0.303],[-0.224,0.197],[0.504,0.517],[-0.139,0.26],[0.706,0.609],[-0.517,0.74],[-0.421,0.451],[-0.628,0.548],[-0.86,0.834],[-0.392,0.255],[-0.043,0.042],[-1.651,8.956],[0.001,0.001],[0.344,0.489],[0.34,0.469],[-0.382,1.057],[0.199,0.114],[-0.736,0.601],[-0.072,0.065],[0.017,0.013],[-0.257,0.296],[-0.5,0.382],[0.074,0.044],[0.024,0.023],[-0.714,1.073],[-0.479,0.456],[0.931,0.712],[-0.376,0.255],[0.324,0.238],[-0.083,0.073],[0.832,0.631],[0.051,0.029],[0.096,0.062],[-0.598,0.506],[1.526,9.647],[-0.211,0.404],[-0.867,0.711],[-1.351,1.962],[0.31,0.228],[0.005,0.008],[0.309,0.529],[-0.21,0.213],[0.374,0.287],[0.177,0.202],[-2.143,3.101],[-0.002,0.001],[0.493,0.948],[-0.524,0.494],[0.016,0.021],[0.235,0.292],[-0.142,0.088],[-1.031,1.726],[0.179,0.23],[-0.423,0.394],[0.082,0.049],[-1.357,5.286],[-1.067,1.012],[-0.381,0.571],[-0.067,0.039],[0.014,0.018],[0.158,0.121],[0.045,0.067],[-0.281,0.538],[-0.36,0.481],[-0.303,0.24],[-0.598,0.7],[0.989,1.329],[0.018,0.026],[-0.157,0.162],[-0.11,0.074],[-0.172,0.159],[-0.031,0.032],[-1.091,3.702],[-0.336,0.278],[-0.189,0.148],[-0.365,0.334],[-0.189,0.381],[0.233,0.254],[-0.218,0.226],[0.342,0.848],[0.07,0.046],[0.217,0.419],[1.25,6.638],[-0.5,1.606],[0.005,0.005],[-0.828,0.655],[-0.029,0.026],[-0.177,0.182],[0.17,0.1],[0.009,0.004],[-0.684,0.474],[0.425,1.012],[-0.101,0.085],[-1.041,0.89],[-0.381,0.741],[0.344,0.224],[0.669,0.787],[0.374,0.585],[-0.005,0.004],[0.565,0.459],[0.407,0.365],[0.05,0.031],[0.012,0.012],[0.685,0.92],[-1.433,1.792],[0.115,0.062],[-0.103,0.163],[-0.724,1.091],[-1.131,4.171],[-0.099,0.051],[-0.138,0.19],[0.274,0.489],[0.421,0.308],[-0.747,0.574],[0.282,0.231],[0.289,0.362],[-0.397,0.632],[-0.133,0.094],[-0.688,1.254],[0.229,0.211],[0.62,0.44],[0.779,1.102],[0.039,0.046],[0.12,0.102],[0.706,0.553],[0.006,0.003],[0.266,0.154],[-0.254,0.226],[-0.224,0.386],[-0.032,0.017],[-0.402,0.241],[0.388,0.366],[-0.276,0.286],[-0.394,0.362],[-0.62,0.435],[1.4,2.637],[0.845,1.251],[-0.23,0.257],[-0.031,0.045],[-0.247,0.201],[0.512,1.025],[0.439,0.307],[-0.262,0.33],[0.186,0.118],[0.151,0.099],[1.6,1.905],[-0.145,0.121],[0.577,0.388],[0.304,0.621],[1.067,1.318],[-0.023,0.013],[0.036,0.026],[0.631,0.662],[0.197,0.111],[-1.235,3.043],[0.629,0.772],[0.563,0.426],[0.005,0.006],[-1.121,0.991],[-0.031,0.036],[0.414,0.587],[0.806,1.686],[-0.635,1.676],[0.071,0.106],[-0.149,0.273],[-0.076,0.04],[-0.067,0.041],[-0.425,0.628],[-0.069,0.065],[-0.341,0.22],[-0.134,0.084],[-0.396,0.237],[-0.311,0.18],[-0.222,0.243],[1.212,1.161],[0.324,0.26],[0.111,0.118],[0.621,1.067],[-0.221,0.429],[0.412,0.247],[-0.709,0.507],[-0.14,0.201],[0.357,0.215],[-0.37,0.24],[-0.162,0.201],[0.919,0.852],[1.09,0.955],[-2.088,3.02],[-0.025,0.014],[-0.963,0.871],[-1.146,1.208],[-0.256,0.179],[0.34,0.457],[0.224,0.154],[-0.149,0.118],[-0.314,0.501],[0.321,0.379],[0.813,0.84],[-1.381,1.546],[-0.161,0.164],[0.83,1.282],[0.349,0.203],[-0.132,0.076],[-0.706,0.615],[-1.344,2.345],[0.471,0.349],[0.056,0.074],[-0.103,0.187],[-0.597,0.447],[-0.029,0.039],[-0.642,0.64],[0.808,2.125],[0.547,0.935],[0.244,0.304],[0.038,0.042],[-1.501,4.46],[0.563,1.187],[-0.762,0.707],[0.447,0.473],[1.043,1.863],[0.572,0.411],[0.581,0.802],[-0.008,0.005],[0.134,0.076],[-1.075,2.274],[-0.036,0.058],[0.508,0.392],[0.997,1.544],[-1.749,12.01],[0.144,0.088],[0.013,0.008],[0.896,0.776],[-1.129,1.019],[-0.002,0.002],[-0.62,0.474],[-0.007,0.006],[-0.339,0.608],[1.044,1.793],[0.716,1.303],[-0.063,0.06],[-0.284,0.307],[0.645,1.017],[-0.157,0.246],[-0.009,0.012],[-0.267,0.16],[0.308,0.323],[0.298,0.687],[-0.184,0.142],[-0.451,0.515],[0.149,0.166],[0.23,0.225],[-0.104,0.145],[0.31,0.305],[0.05,0.076],[-0.593,0.701],[0.241,0.267],[-0.788,0.635],[0.924,0.73],[0.144,0.15],[0.596,0.993],[-0.068,0.035],[-0.548,0.926],[-0.867,0.785],[0.924,0.702],[-0.394,0.265],[-0.228,0.486],[0.072,0.117],[-0.128,0.098],[-0.352,0.544],[-1.502,1.944],[-0.223,0.186],[-0.904,1.775],[-0.111,0.138],[-0.097,0.054],[-0.136,0.186],[1.786,2.435],[0.477,0.316],[0.638,0.734],[-0.362,0.936],[0.061,0.082],[-0.084,0.097],[0.562,0.535],[1.285,1.581],[-0.003,0.003],[0.186,0.175],[0.332,0.537],[0.465,0.894],[0.6,0.638],[-0.343,0.206],[-0.67,0.606],[-1.834,3.316],[0.863,1.241],[0.033,0.052],[0.057,0.033],[0.038,0.036],[0.132,0.257],[0.881,0.693],[0.609,0.503],[-1.672,1.74],[-0.762,1.452],[-1.353,1.643],[0.398,0.347],[-0.753,0.943],[0.465,0.319],[-0.237,0.529],[0.129,0.099],[-0.001,0.001],[-0.573,0.62],[1.49,5.091],[0.16,0.327],[1.595,2.375],[0.198,0.325],[-0.091,0.129],[-0.079,0.048],[-0.319,0.233],[-0.332,0.698],[-0.483,1.523],[0,-0],[1.103,0.911],[0.206,0.157],[-0.107,0.124],[0.317,0.368],[0.112,0.071],[0.186,0.252],[1.535,10.34],[-0.044,0.064],[0.532,0.526],[0.168,0.126],[-1.108,0.923],[0.147,0.276],[1.285,1.315],[0.094,0.119],[1.094,1.331],[0.215,0.2],[0.206,0.232],[-1.682,7.519],[-0.894,1.4],[-0.502,0.6],[-0.13,0.067],[-0.685,0.567],[-0.609,0.932],[-0.023,0.017],[-0.218,0.259],[1.202,1.806],[0.039,0.04],[1.993,2.397],[0.139,0.205],[0.022,0.017],[0.358,0.29],[0.28,0.226],[0.389,0.356],[-0.704,2.622],[0.69,0.527],[0.028,0.021],[-1.959,3.377],[-0.881,2.101],[-0.122,0.185],[-0.418,0.89],[-0.13,0.125],[-1.217,1.24],[0.143,0.113],[0.779,1.025],[0.202,0.109],[-1.105,1.09],[0.068,0.088],[0.131,0.172],[-0.02,0.017],[-0.357,0.954],[0.342,0.239],[0.596,0.628],[0.414,0.619],[-0.321,0.213],[0.221,0.249],[0.353,0.206],[-1.711,6.323],[-0.105,0.062],[0.09,0.151],[0.261,0.163],[-0.138,0.274],[0.667,1.222],[0.836,1.197],[0.375,0.313],[-0.173,0.284],[-0.355,0.458],[-0.66,0.713],[-0.361,0.29],[-1.132,1.181],[0.139,0.209],[-0.491,0.843],[-1.362,3.244],[-1.209,2.148],[1.64,9.82],[1.553,5.26],[0.24,0.21],[-1.379,2.47],[0.245,0.18],[1.132,3.398],[-1.102,1.656],[0.065,0.071],[0.274,0.362],[-0.029,0.016],[0.04,0.034],[-0.472,0.741],[0.135,0.235],[-0.315,0.211],[1.425,3.085],[0.21,0.165],[1.635,11.11],[-1.022,2.305],[0.478,0.514],[-0.658,1.142],[1.122,0.963],[0.718,0.746],[3.213,7.075],[-0.224,0.3],[-0.808,0.623],[0.47,0.323],[-0.008,0.004],[0.523,0.682],[-0.193,0.198],[-0.345,0.461],[0.411,0.349],[-1.744,4.578],[0.256,0.553],[0.329,0.284],[-0.143,0.086],[0.089,0.065],[0.125,0.148],[-0.324,0.617],[-0.367,0.25],[0.205,0.116],[0.436,1.194],[0.194,0.377],[0.321,0.204],[0.367,0.451],[0.171,0.189],[-0.427,0.288],[0.829,0.65],[-0.505,0.557],[-0.455,0.483],[0.098,0.123],[1.496,4.697],[-0.226,0.247],[0.594,0.532],[-0.053,0.068],[0.223,0.203],[-0.914,0.821],[-0.375,0.541],[1.15,1.234],[1.06,3.154],[0.028,0.024],[-1.842,1.996],[0.358,0.653],[-0.041,0.049],[0.13,0.187],[0.208,0.144],[0.265,0.158],[-0.172,0.162],[0.305,0.209],[0.04,0.049],[-0.038,0.062],[0.423,0.978],[-0.179,0.149],[-0.342,0.749],[-1.306,1.435],[-0.026,0.036],[-0.177,0.258],[-0.055,0.082],[0.033,0.027],[1.293,1.519],[0.146,0.285],[-0.084,0.074],[0.542,0.692],[-0.218,0.12],[1.742,6.859],[-0.305,0.219],[-0.059,0.034],[-1.322,1.243],[-0.133,0.207],[1.055,1.205],[-0.077,0.08],[0.705,0.592],[0.282,0.182],[0.039,0.025],[-1.124,2.064],[0.281,0.325],[-0.223,0.264],[-0.234,0.148],[-0.251,0.226],[0.849,1.156],[-0.481,0.635],[-1.735,2.148],[0.206,0.233],[0.251,0.355],[-0.096,0.07],[-0.147,0.087],[0.461,0.987],[-0.885,1.517],[-0.599,0.551]]},"x":null,"z":{"Group":["NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Decreased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Increased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Increased","Decreased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Decreased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Decreased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Increased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Increased","NoChange","NoChange","NoChange","Increased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Increased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Decreased","NoChange","Increased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Increased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Increased","NoChange","NoChange","Decreased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Increased","NoChange","NoChange","NoChange","Increased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Decreased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Increased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Increased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Decreased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Decreased","NoChange","NoChange","NoChange","NoChange","Decreased","NoChange","NoChange","NoChange","Increased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Increased","NoChange","NoChange","Decreased","NoChange","NoChange","NoChange","NoChange","Increased","Decreased","NoChange","NoChange","NoChange","Increased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Increased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Increased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Increased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Decreased","NoChange","NoChange","Decreased","NoChange","NoChange","NoChange","NoChange","NoChange","Decreased","NoChange","NoChange","Increased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Decreased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Decreased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Decreased","Decreased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Increased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Decreased","NoChange","NoChange","NoChange","NoChange","Increased","NoChange","NoChange","NoChange","NoChange","Decreased","NoChange","NoChange","Increased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Decreased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Decreased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Decreased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Decreased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Increased","NoChange","NoChange","Decreased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Decreased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Decreased","NoChange","NoChange","NoChange","Decreased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Decreased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Increased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Decreased","NoChange","NoChange","NoChange","Decreased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Increased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Increased","NoChange","NoChange","NoChange","Increased","NoChange","NoChange","NoChange","NoChange","Decreased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Decreased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Decreased","NoChange","NoChange","NoChange","NoChange","NoChange","Decreased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Decreased","NoChange","NoChange","NoChange","Increased","NoChange","NoChange","NoChange","NoChange","Decreased","NoChange","NoChange","NoChange","Decreased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Increased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Decreased","NoChange","NoChange","NoChange","NoChange","NoChange","Increased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Increased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Decreased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Decreased","NoChange","Decreased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Increased","NoChange","Increased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Increased","NoChange","NoChange","NoChange","NoChange","NoChange","Increased","NoChange","Increased","NoChange","NoChange","Decreased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Increased","NoChange","Increased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Decreased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Decreased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Decreased","Decreased","Increased","Increased","NoChange","Decreased","NoChange","Increased","Decreased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Increased","NoChange","Increased","Decreased","NoChange","NoChange","NoChange","NoChange","Increased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Decreased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Increased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Increased","NoChange","Decreased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Decreased","NoChange","NoChange","NoChange","NoChange","Increased","NoChange","NoChange","NoChange","NoChange","Increased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Decreased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","Decreased","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange","NoChange"],"FC":["1.46","1.85","1.41","1.16","1.02","1.40","1.01","1.43","2.32","2.11","1.10","1.24","1.20","1.15","1.47","1.67","1.22","1.17","1.06","1.97","1.33","1.17","1.23","1.08","1.58","1.12","1.57","1.41","1.40","1.24","1.24","1.13","1.11","1.02","2.04","1.41","1.84","1.98","1.25","1.33","1.05","1.09","1.27","1.60","1.81","1.41","2.69","1.55","1.22","1.40","1.56","1.59","1.23","1.08","2.15","2.73","1.73","1.24","1.35","1.05","1.56","1.16","1.19","1.17","1.16","1.07","1.71","1.18","3.13","1.47","1.39","1.07","1.14","1.02","1.37","1.91","1.02","1.42","1.18","1.85","1.09","2.27","1.20","1.58","1.15","1.46","1.02","1.28","1.04","1.13","1.37","2.82","1.55","1.14","1.08","1.24","2.03","1.47","1.01","1.74","1.45","1.01","2.07","1.31","1.09","1.16","2.12","1.07","1.46","1.93","1.26","1.30","1.69","1.20","1.74","1.86","1.26","2.58","1.20","1.02","1.29","1.06","2.00","1.15","1.46","1.01","1.21","1.37","1.40","1.91","1.04","1.52","3.41","1.20","2.15","1.02","1.94","1.14","1.29","2.04","1.25","1.92","1.53","1.14","1.26","1.49","1.65","1.28","2.58","1.03","1.11","1.49","1.08","1.58","1.33","1.12","1.01","1.97","1.21","1.38","1.08","1.07","1.10","2.58","1.02","1.34","2.07","1.10","1.79","1.02","2.08","1.00","1.10","1.56","1.74","1.20","1.44","1.28","1.15","1.19","1.10","1.45","1.26","1.25","1.15","1.26","2.20","1.07","1.23","1.14","1.31","1.57","2.88","1.54","1.06","1.97","2.30","1.17","1.03","1.30","1.41","1.50","1.26","3.60","1.13","1.52","1.07","1.15","1.85","1.26","1.42","2.43","1.03","1.07","1.69","1.72","1.74","1.37","1.01","2.33","1.78","1.17","1.13","1.34","1.13","1.22","1.01","1.30","1.04","1.10","1.44","1.09","1.71","1.01","1.32","1.06","1.23","1.20","1.55","1.16","1.14","1.37","1.39","1.07","1.03","1.34","1.45","1.14","1.16","1.14","1.23","1.23","1.35","1.09","1.44","2.01","1.07","1.02","1.25","1.34","1.27","1.24","1.28","1.21","1.03","1.25","1.64","1.08","1.11","1.53","1.28","2.77","1.66","1.95","1.07","1.06","2.06","1.05","1.09","1.21","3.17","1.23","1.07","1.14","1.92","1.44","1.11","1.44","2.75","1.24","1.00","2.60","1.36","1.39","1.05","1.27","3.97","3.51","2.07","1.11","1.10","3.15","1.19","1.20","1.17","1.99","1.04","1.03","2.03","1.99","1.56","1.93","1.17","1.11","1.12","1.13","1.92","2.45","1.58","1.49","1.58","1.48","1.23","1.77","1.02","1.18","1.06","1.38","1.14","1.57","1.09","1.03","1.41","1.14","2.01","1.44","1.02","1.54","1.45","1.20","1.28","1.27","1.15","1.16","1.05","1.25","1.02","1.14","1.46","1.16","1.53","1.38","1.05","1.02","1.08","1.09","1.26","2.83","1.37","1.13","4.34","1.10","1.89","1.15","1.31","1.24","7.75","1.03","1.07","2.39","1.23","1.14","1.44","1.07","1.00","1.11","1.22","1.54","1.30","1.03","1.02","1.54","1.18","1.14","1.27","1.26","1.85","1.34","2.66","1.03","1.00","1.47","1.06","1.24","1.06","1.48","1.54","1.88","1.24","1.33","1.20","1.19","1.03","1.77","1.09","1.06","2.47","1.14","2.43","1.01","1.04","1.29","1.54","1.11","1.01","1.68","1.23","1.15","1.18","1.27","1.06","1.26","1.49","1.42","1.34","2.29","3.99","2.07","1.10","1.32","1.14","1.48","1.05","1.00","2.50","1.09","1.06","2.40","1.36","1.53","1.81","1.27","1.01","1.24","1.56","1.40","1.11","1.68","1.21","3.06","1.17","1.88","1.24","1.89","3.08","1.60","1.19","1.69","1.09","3.79","1.76","1.05","3.49","1.04","1.31","1.06","1.54","1.02","1.45","1.96","1.02","1.32","2.16","1.59","2.60","1.14","1.04","1.29","1.03","1.90","1.92","1.09","1.95","1.94","1.33","2.14","1.54","1.96","2.17","1.27","2.12","1.21","1.03","1.56","1.75","1.06","1.45","1.03","1.45","3.39","1.92","1.34","1.17","1.42","1.10","1.63","1.43","1.34","1.55","1.82","1.31","1.03","3.14","1.00","1.27","1.27","1.30","1.15","1.67","1.05","1.01","1.19","1.41","1.05","1.02","1.64","1.39","1.91","1.30","1.25","1.06","1.78","1.04","1.07","1.51","2.88","1.16","1.82","2.55","1.24","1.00","1.24","1.16","1.30","1.13","4.42","1.00","1.41","1.44","1.01","1.18","1.10","2.04","1.13","1.34","1.06","2.56","2.10","1.30","1.05","1.01","1.12","1.03","1.22","1.28","1.23","1.51","1.98","1.01","1.11","1.08","1.13","1.02","2.13","1.26","1.14","1.29","1.14","1.18","1.16","1.27","1.05","1.16","2.38","1.41","1.00","1.78","1.02","1.13","1.13","1.01","1.61","1.34","1.07","2.06","1.30","1.27","1.59","1.30","1.00","1.48","1.33","1.04","1.01","1.61","2.70","1.08","1.07","1.65","2.19","1.07","1.10","1.21","1.34","1.68","1.22","1.22","1.32","1.10","1.61","1.17","1.54","1.72","1.03","1.09","1.63","1.00","1.20","1.19","1.17","1.02","1.32","1.31","1.21","1.31","1.54","2.64","1.80","1.17","1.02","1.19","1.43","1.36","1.20","1.14","1.11","3.03","1.11","1.49","1.23","2.10","1.02","1.03","1.55","1.15","2.35","1.55","1.48","1.00","2.17","1.02","1.33","1.75","1.55","1.05","1.11","1.05","1.05","1.34","1.05","1.27","1.10","1.32","1.24","1.17","2.32","1.25","1.08","1.54","1.17","1.33","1.63","1.10","1.28","1.29","1.12","1.89","2.13","4.25","1.02","1.95","2.21","1.19","1.27","1.17","1.11","1.24","1.25","1.76","2.60","1.12","1.78","1.27","1.10","1.63","2.54","1.39","1.04","1.07","1.51","1.02","1.56","1.75","1.46","1.18","1.03","2.83","1.48","1.70","1.36","2.06","1.49","1.50","1.01","1.10","2.11","1.03","1.42","2.00","3.36","1.10","1.01","1.86","2.19","1.00","1.54","1.00","1.26","2.06","1.64","1.04","1.22","1.56","1.11","1.01","1.20","1.24","1.23","1.14","1.37","1.11","1.17","1.07","1.24","1.04","1.51","1.18","1.73","1.90","1.10","1.51","1.05","1.46","1.82","1.90","1.31","1.17","1.05","1.09","1.28","2.83","1.17","1.87","1.08","1.07","1.10","3.45","1.39","1.56","1.29","1.04","1.06","1.48","2.44","1.00","1.14","1.26","1.38","1.52","1.27","1.59","3.57","1.82","1.02","1.04","1.03","1.10","1.84","1.53","3.19","1.70","2.55","1.32","1.69","1.38","1.18","1.09","1.00","1.49","2.81","1.12","3.02","1.15","1.07","1.06","1.25","1.26","1.40","1.00","2.15","1.15","1.08","1.25","1.08","1.14","2.90","1.03","1.45","1.12","2.16","1.11","2.44","1.07","2.13","1.16","1.15","3.21","1.86","1.42","1.09","1.61","1.53","1.02","1.16","2.30","1.03","3.98","1.10","1.02","1.28","1.21","1.31","1.63","1.61","1.02","3.89","1.84","1.09","1.34","1.09","2.32","1.10","1.72","1.15","2.15","1.05","1.10","1.01","1.28","1.27","1.51","1.33","1.25","1.17","1.28","3.27","1.08","1.06","1.20","1.10","1.59","1.79","1.30","1.13","1.28","1.58","1.28","2.19","1.10","1.41","2.57","2.31","3.12","2.93","1.18","2.60","1.19","2.19","2.15","1.05","1.21","1.02","1.03","1.39","1.10","1.24","2.69","1.16","3.11","2.03","1.39","1.58","2.18","1.64","9.27","1.17","1.75","1.39","1.01","1.44","1.14","1.27","1.33","3.35","1.19","1.26","1.10","1.06","1.09","1.25","1.29","1.15","1.35","1.14","1.25","1.29","1.13","1.34","1.78","1.42","1.37","1.07","2.82","1.17","1.51","1.04","1.17","1.88","1.30","2.22","2.08","1.02","3.59","1.28","1.03","1.09","1.16","1.20","1.13","1.24","1.03","1.03","1.34","1.13","1.27","2.47","1.02","1.13","1.04","1.02","2.45","1.11","1.06","1.46","1.16","3.34","1.24","1.04","2.50","1.10","2.08","1.05","1.63","1.22","1.03","2.18","1.22","1.17","1.18","1.19","1.80","1.40","3.33","1.15","1.19","1.07","1.11","1.38","1.85","1.51"]}},"config":{"graphType":"Scatter2D","isR":true,"xAxis":["logFC"],"yAxis":["-log-pVal"],"colorBy":"Group","colorKey":{"Group":{"Increased":"rgba(197,27,38,0.75)","Decreased":"rgba(33,102,172,0.75)","NoChange":"rgba(150,150,150,0.35)"}},"sizeBy":"FC","sizes":[3,6,9,12,15],"title":"Publication-ready volcano plot","xAxisTitle":"log2 fold change","yAxisTitle":"-log10 p-value","showDecorations":true,"decorations":{"line":[{"color":"rgba(120,120,120,0.8)","width":1,"x":1},{"color":"rgba(120,120,120,0.8)","width":1,"x":-1},{"color":"rgba(120,120,120,0.8)","width":1,"y":1.301}]}},"events":null,"afterRender":null},"evals":[],"jsHooks":[]}</script>
</div>
</div>
<p>The chart is interactive: hover a point for its gene and values, drag to zoom, or use the toolbar to filter by regulation group. The dashed guides mark the ±1 log2FC and the p = 0.05 cutoffs.</p>
</section>
<section id="why-reproducible" class="level2">
<h2 class="anchored" data-anchor-id="why-reproducible">Why “reproducible”</h2>
<p>Everything above serializes to one JSON specification — the <code>data</code> and the <code>config</code>. That spec is portable: the identical figure renders from the Python (<code>canvasxpress</code>) and JavaScript packages, and it can be validated against a published schema and re-rendered later, so a figure in a paper can be regenerated and audited rather than just looked at.</p>
</section>
<section id="where-to-go-next" class="level2">
<h2 class="anchored" data-anchor-id="where-to-go-next">Where to go next</h2>
<ul>
<li>Gallery of examples: <a href="https://canvasxpress.org/examples.html" class="uri">https://canvasxpress.org/examples.html</a></li>
<li>From your object (survival tables, expression matrices, single-cell): <a href="https://canvasxpress.org/migrate.html" class="uri">https://canvasxpress.org/migrate.html</a></li>
<li>Package &amp; issues: <a href="https://github.com/neuhausi/canvasXpress" class="uri">https://github.com/neuhausi/canvasXpress</a></li>
</ul>


</section>

 ]]></description>
  <category>R</category>
  <category>canvasXpress</category>
  <category>bioinformatics</category>
  <category>visualization</category>
  <guid>https://neuhausi.github.io/canvasxpress-blog/posts/r/volcano-plots-in-r/</guid>
  <pubDate>Fri, 18 Sep 2026 04:00:00 GMT</pubDate>
  <media:content url="https://neuhausi.github.io/canvasxpress-blog/posts/r/volcano-plots-in-r/thumbnail.png" medium="image" type="image/png" height="108" width="144"/>
</item>
</channel>
</rss>
