I have a data set where x
represents day of year (say birthdays) and I want to create a density graph of this.
Further, since I have some grouping information (say boys or girls), I want to use the capabilities of ggplot2
to make a density plot.
Easy enough at first:
require(ggplot2); require(dplyr)
bdays <- data.frame(gender = sample(c('M', 'F'), 100, replace = T), bday = sample(1:365, 100, replace = T))
bdays %>% ggplot(aes(x = bday)) + geom_density(aes(color = factor(gender)))
However, this gives a poor estimate because of edge effects.
I want to apply the fact that I can use circular coordinates so that 365 + 1 = 1 -- one day after December 31st is January 1st.
I know that the circular
package provides this functionality, but I haven't had any success implementing it using a stat_function()
call.
It's particularly useful for me to use ggplot2
because I want to be able to use facets, aes
calls, etc.
Also, for clarification, I would like something that looks like geom_density
-- I am not looking for a polar plot like the one shown at: Circular density plot using ggplot2.