-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expose argument n from stats::density in the interface of stat_density. #1661
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Current coverage is 65.53%@@ master #1661 diff @@
==========================================
Files 158 158
Lines 5547 5548 +1
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
+ Hits 3635 3636 +1
Misses 1912 1912
Partials 0 0
|
@@ -4,6 +4,8 @@ | |||
#' \code{\link{density}} for details | |||
#' @param kernel kernel used for density estimation, see | |||
#' \code{\link{density}} for details | |||
#' @param n number of equally spaced points at which the density is to be |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please add a note about powers of two being faster? (IIRC)
This looks reasonable. Would you mind including a couple of plots in this PR just to verify that is works? (i.e. picking a really extreme n) |
I have added a note about powers of two being recommended – though n is rounded to the nearest power of two automatically if n > 512. Here are the requested plots (for n = 512, 64, 16, and 4).
|
The argument controls the number of equally spaced points at which the density is to be estimated. As in stats::density the argument n defaults to 512. It is exposed through the function interface of stat_density and can thus also be used from geom_density. An existent local variable n, which holds the number of values in the input vector, has been renamed to nx to avoid a name clash.
Thanks! |
This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/ |
The argument controls the number of equally spaced points at which the density is to be estimated. As in
stats::density
the argumentn
defaults to 512. It is exposed through the function interface ofstat_density
and can thus also be used fromgeom_density
.An existent local variable
n
, which holds the number of values in the input vector, has been renamed tonx
to avoid a name clash.I needed this argument because plots created with
geom_density
contained a large number of points (1024?) per density curve. This resulted in large file sizes when saving the plot as a vector graphic. I think that it is generally useful to be able to control this parameter of the density function.I rebuild the documentation, and tested the new functionality. However, I added a new argument to an existing function and – not being an R expert – I am not sure whether this might break someones code. The argument has a default value, but I did not add it at the very end of the argument list but rather at a point where it seemed fitting.