Note that there are some explanatory texts on larger screens.

plurals
  1. POR plot: how to make a histogram with horizontal lines using plot()
    primarykey
    data
    text
    <p>How can I use <code>plot</code> to turn this plot sideways so the histogram bars are horizontal?</p> <pre><code>size&lt;- abs(rnorm(20,10,10)) age&lt;-c(seq(1, 20, by=2)) plot(size~age, type=("n")); lines(size~age, type=c("l"), lines(size~age, type=c("h"))) </code></pre> <p><img src="https://i.stack.imgur.com/EckXI.png" alt="enter image description here"></p> <p>What I want is roughly something like this, with the histogram lines horizontal:</p> <p><img src="https://i.stack.imgur.com/Vc0Nh.png" alt="enter image description here"></p> <p>which I did with </p> <pre><code>plot(size~age, type=("n"), yaxt="n", xaxt="n", ylab=""); lines(size~age, type=c("l"), lines(size~age, type=c("h"))); axis(4); axis(1,las=2) </code></pre> <p>and then rotating the image output in other software. </p> <p>I'd like to know how I can use the <code>plot</code> function to get the output plot sideways so I can make groups of them in <code>R</code> without having to rotate them outside of <code>R</code>. </p> <p><strong>UPDATE</strong> Thanks to the very helpful suggestion from @csgillespie I've got this, which has got me on my way:</p> <pre><code>size&lt;- abs(rnorm(20,10,10)) age&lt;-c(seq(1, 40, by=2)) # sorry for the typo in the first set of example data above plot(-age~size, type="n",yaxt="n", ylab="Age", xlab="Size") lines(-age~size) segments(0, -age, size, -age) axis(2, labels=c(seq(0,max(age), by=5)), at=-c(seq(0,max(age), by=5)), las=1) # this is a more general approach to labelling the axis ticks </code></pre> <p>and here's resulting plot (not pretty yet, but I think I can do the rest from here):</p> <p><img src="https://i.stack.imgur.com/6isNJ.png" alt="enter image description here"></p>
    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