hannes101 hannes101 - 15 days ago 6
R Question

Density function plot not really vertical - ggplot2

I am plotting a density function with the

ggplot2
package. I noticed that the first and second vertical line are not perfectly rectangular, although as far as I understand it should be, or? I also found this to be the case, when plotting a distribution of the binomial distribution that the the steps are not really rectangular.

library(ggplot2)
p_uniform_density <- ggplot(data.frame(x = c(-2, 17.5)), aes(x)) +
stat_function(fun = dunif, args = list(min = 0, max = 15), size=1.2 ) +
theme_bw() +
labs(y = "f(X)", x = "X") +
theme(text = element_text(size=20) , panel.grid.major = element_line(size = 0.2, linetype = 'solid', colour = "grey"),
panel.grid.minor = element_line(size = 0.1, linetype = 'solid', colour = "grey")) +
scale_x_continuous( breaks = c(-2:17.5))


Density plot with skewed start and end values

Answer

try with n=1e3 in stat_function

Comments