Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's your first 2 questions:</p> <pre><code> myhist &lt;- hist(x,prob=FALSE,col="gray",xlim=c(0,100)) dens &lt;- density(x) axis(side=1, at=seq(0,100, 20), labels=seq(0,100,20)) lines(dens$x,dens$y*(1/sum(myhist$density))*length(x)) </code></pre> <p>The histogram has a bin width of 5, which is also equal to <code>1/sum(myhist$density)</code>, whereas the <code>density(x)$x</code> are in small jumps, around .2 in your case (512 even steps). <code>sum(density(x)$y)</code> is some strange number definitely not 1, but that is because it goes in small steps, when divided by the x interval it is approximately 1: <code>sum(density(x)$y)/(1/diff(density(x)$x)[1])</code> . You don't need to do this later because it's already matched up with its own odd x values. Scale 1) for the bin width of <code>hist()</code> and 2) for the frequency of x <code>length(x)</code>, as DWin says. The last axis tick became visible after setting the <code>xlim</code> argument.</p> <p>To do your problem 2, set up a plot with the correct dimensions (<code>xlim</code> and <code>ylim</code>), with <code>type = "n"</code>, then draw 3 lines for the densities, scaled using something similar to the density line above. Think however about whether you want those semi continuous lines to reflect the heights of imaginary bars with bin width 5... You see how that might make the density lines exaggerate the counts at any particular point?</p> <p><img src="https://i.stack.imgur.com/P6BQv.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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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