Note that there are some explanatory texts on larger screens.

plurals
  1. POPlotting a double y axis when x and y lenghts differ
    primarykey
    data
    text
    <p>I have two large data sets that I read into R. For simplicity, consider the following:</p> <pre><code>##Data set 1 x = c("2005", "2006", "2007", "2008", "2009", "2010") y = c(1,2,4,6,4,3) ##Data set 2 ##Shorter than D2. Missing 2005 x1 = c( "2006", "2007", "2008", "2009", "2010") y1 = c(20,40,60,50,29) </code></pre> <p>I want to plot both datasets as line plots with a double y axis. Ideally plotting would like this:</p> <pre><code>plot(x, y, type = "o", col = "red") par(new = TRUE) plot(x, y1, type = "o", col = "blue", xaxt = "n", yaxt = "n", xlab = "", ylab = "") axis(4) </code></pre> <p>But of course the <code>x</code> any <code>y1</code> are not the same size so I get an error. I've tried</p> <pre><code>plot(x1, y1, type = "o", col = "blue", xaxt = "n", yaxt = "n", xlab = "", ylab = "") </code></pre> <p>but then <code>y1</code> just gets stretch out to cover the entire length of.</p> <p>In this simple case I could just add a blank row of <code>Y1</code> to cover the missing 2005 data, but it's not a practical solution in my real data. Is there anyway I can tell R to line up the two datasets accordingly?</p> <p>Additionally, I would prefer to use gplots because I love the easy ability to offset my error bars. The code might look something like this </p> <pre><code>SE = c(.20,.40,.60,.50,.29) SE1 = c(.20,.40,.60,.50,.29) offset = .08 plotCI(x = x, y = y, uiw = SE, type = "o",col = "red") par(new = TRUE) plotCI(x = (x1) + offset, y = y1, type = "o", uiw = SE1, col = "blue", xaxt = "n", yaxt = "n", xlab = "", ylab = "") axis(4) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload