x <- data.frame(x = rnorm(n = 100, mean = 1, sd = 1))ggplot(data = x, mapping = aes(x = x)) + geom_histogram(binwidth = 0.5)
ggplot(data = x, mapping = aes(x = x)) +geom_histogram(mapping = aes(y = ..density..), binwidth = 0.5) +stat_function(fun = dnorm, args = list(mean = mean(x$x), sd = sd(x$x)), color = "black") +geom_vline(mapping = aes(xintercept = mean(x = x, na.rm = T)), color = "red", linetype = "dashed", size = 1)
ggplot(data = x, aes(x = x)) +stat_bin(binwidth = 0.5, color = "black", fill = NA) +stat_function(fun = dnorm.count, args = list(mean = mean(x$x), sd = sd(x$x), n = nrow(x), binwidth = 0.5), color = "red") +geom_vline(mapping = aes(xintercept = mean(x = x, na.rm = T)), color = "red", linetype = "dashed", size = 1) +stat_bin(binwidth = 0.5, geom = "text", mapping = aes(label = ..count..), vjust = -0.5)
dnbinom.count <- function(x, mu , size, log = FALSE, n = 1, binwidth = 1){n * binwidth * dnorm(x = x, mu = mu, size = size, log = log)}y <- data.frame(y = rnbinom(n = 1000, mu = 5, size = 8))ggplot(data = y, aes(x = y)) +stat_bin(binwidth = 1, color = "black", fill = NA) +stat_function(fun = dnbinom.count, args = list(mu = mean(y$y), size = sd(y$y)^2, n = nrow(y), binwidth = 1), color = "red") +geom_vline(mapping = aes(xintercept = mean(x = y, na.rm = T)), color = "red", linetype = "dashed", size = 1) +stat_bin(binwidth = 1, geom = "text", mapping = aes(label = ..count..), vjust = -0.5)
Warning message:Computation failed in `stat_function()`:unused arguments (mu = mu, size = size)
Shouldn’t your dnbinom.count function instead call dnbinom (and not dnorm)?
--
--
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.