Epidemiological epicurve

48 views
Skip to first unread message

Yuster Ronoh

unread,
Jul 19, 2014, 7:19:46 AM7/19/14
to ggp...@googlegroups.com

Dear list members I have the dataset  and I want to construct the epicurve similar to this. 

This is the code I used
>flu <- read.csv("C:/Users/symon/Desktop/flu epicurve.csv")
> require(date)
 # Format the date
> flu$Date_epi <- strptime(flu$Date_epi, format= "%d/%m/%Y")
>format(flu$Date_epi, format="%Y-%m-%d")
> str(flu)
# plot the epicurve
> hist(flu$Date_epi[(flu$Sex=="F")], "weeks", 
    format = "%d %b %Y", freq=T, col=rgb(0,0,0,1), axes=F, main="")
> hist(flu$Date_epi[(flu$Sex=="M")], "weeks", 
     format = "%d %b %y", freq=T, col=rgb(0,0,0,1), axes=F, main="")
> axis.Date(1, at=seq(as.Date("2014-06-03"), as.Date("2014-07-19"), by="1 week"), format="%d %b %y")
> axis.Date(1, at=seq(as.Date("2014-06-03"), as.Date("2014-07-19"), by="weeks"), 
          labels=F, tcl= -0.5)
But this is what I obtain(two different graph) than what I expected) could anyone help me plot the epicurve similar to the above
​​
Influenza data.txt

Roman Luštrik

unread,
Jul 19, 2014, 8:41:52 AM7/19/14
to Yuster Ronoh, ggplot2
What about something like this?

flu$Date_epi <- strptime(flu$Date_epi, format= "%Y-%m-%d")

library(ggplot2)
ggplot(flu, aes(x = Date_epi, fill = Classification)) +
  theme_bw() +
  geom_histogram(position = "dodge")

I don't know which variable you want to use to group the data, I chose Classification.

Cheers,
Roman


--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
In God we trust, all others bring data.

Yuster Ronoh

unread,
Jul 19, 2014, 10:06:19 AM7/19/14
to Roman Luštrik, ggplot2
Thanks Roman for swift reply. The variables I am intending to use are Date_epi for epidemiological weeks by Sex since the data was abstracted from all patients tested positive Influenza A.
I ran the code but I run to an error and could not figured it out to manouver it.
> ggplot(flu, aes(x = Date_epi, fill = Classification)) +
+   theme_bw() +
+   geom_histogram(position = "dodge")
stat_bin: binwidth defaulted to range/30. Use 'binwidth = x' to adjust this.
Error in exists(name, envir = env, mode = mode) : 
  argument "env" is missing, with no default
Reply all
Reply to author
Forward
0 new messages