?density
notes that:
bw
the smoothing bandwidth to be used. The kernels are scaled such that this is the standard deviation of the smoothing kernel.
So bw = 3600*24*7/sqrt(12)
appears to give one-week wide shapes. In other words, you need to "de-scale" your bandwith, so that when it is scaled by density
you get what you want. You can alternatively set adjust = 1/sqrt(12)
.
To make to shapes have vertical drop-offs, increase n
to improve the computational resolution, eg n = 2^15
.
So change your density
call to:
ds <- density(as.numeric(daysPosix),
bw = 3600 * 24 * 7 / sqrt(12),
kernel = "rectangular",
cut = 3, n=2^15)
And checking the width of the shapes:
which(abs(diff(ds$y))>max(ds$y)/2) # approximate locations of the edges
[1] 1197 4469 28299 31571
(ds$x[4469]-ds$x[1197])/(3600*24*7)
[1] 1.00034