Note that there are some explanatory texts on larger screens.

plurals
  1. POFormatting histogram x-axis when working with dates using R
    primarykey
    data
    text
    <p>I am in the process of creating an epidemic curve (histogram of number of cases of a disease per day) using R, and am struggling a little with formatting the x-axis.</p> <p>I am aware that ggplot gives very nice graphs and easily manipulatable axes ( <a href="https://stackoverflow.com/questions/10770698/understanding-dates-and-plotting-a-histogram-with-ggplot2-in-r">Understanding dates and plotting a histogram with ggplot2 in R</a> ), but in this case I prefer to use the <code>hist()</code> command, because I am describing 2 different patterns at the same time, as below (I don't think you can do something similar in ggplot):</p> <p><img src="https://i.stack.imgur.com/1af2C.jpg" alt="enter image description here"></p> <p>The problem here is that the x-axis does not begin at the first case, has too many tick marks, and I'd like to be able to have a systematic date marker, eg. every 7 days, or every 1st of the month. </p> <p>The data are stored in a database (dat.geo) as one row per suspected case, with info on date of onset and suburb (whether black or white in histogram), as below: </p> <pre><code>&gt; head(dat.geo) number age sex suburb Date_of_Onset 1 1 12 F x 2011-10-11 2 2 28 M x 2011-10-10 3 3 15 F x 2011-10-12 4 4 12 M y 2011-10-25 5 5 10 F x 2011-10-15 6 6 9 M y 2011-10-20 </code></pre> <p>Here is my code:</p> <pre><code>pdf(file='1.epi.curve.pdf') hist(dat.geo$Date_of_Onset[(dat.geo$suburb=="x")], "days", format = "%d %b %y", freq=T, col=rgb(0,0,0,1), axes=T, main="", add=T) hist(dat.geo$Date_of_Onset[(dat.geo$suburb=="y")], "days", format = "%d %b %y", freq=T, main="", col=rgb(1,1,1,.6), add=T, axes=F) dev.off() </code></pre> <p>I have tried suppressing the axis and adding a manipulated one later using this code</p> <pre><code>axis(1, labels=T) axis(2) </code></pre> <p>but this is what I get (and I have no idea how to manipulate that):</p> <p><img src="https://i.stack.imgur.com/zUKPy.jpg" alt="enter image description here"></p> <p>Your help is greatly appreciated!</p> <p>thanks</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.
 

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