Let's consider my ggplot
function for histogram:
library(ggplot2)
get_histogram <- function(vec, width) {
df <- data.frame(vec)
temp <- ggplot2::ggplot(df, aes(x = vec)) +
# Delete x axis name and add plot title
labs(
x = NULL,
title = "Empirical histogram vs standard normal density"
) +
# Center plot title
theme(plot.title = element_text(hjust = 0.5)) +
# Add histogram with respect to given bin width
geom_histogram(
binwidth = width,
aes(y = stat(density)),
fill = I("blue"),
col = I("red"),
alpha = I(.2)
) +
# Adding probability density function of standard normal distribution.
stat_function(fun = function(x) {
stats::dnorm(x, mean = 0, sd = 1)
})
temp
}
Let's see how it works:
get_histogram(rnorm(100), width = 0.4)
However I will see error:
no visible binding for global variable 'density'
when running pacakge checks. Do you know where is the problem? I tried to find it, but it seems that most of those errors is connected with dplyr
package rather than ggplot