Plot curves using ggplot

How can I replicate the folllowing plot using ggplot?

library(kde1d)
set.seed(100)
x=sample(1000,100)
fit <- kde1d(x,bw = 92)
plot(NULL, xlim = c(0, 1000), ylim = c(0, 1), axes = TRUE, 
     xlab = "Value",
     ylab = expression("Probability"))
curve(pkde1d(x, fit), 
      add = TRUE, col = "black", lwd = 1.5)

Thank you

Does this get you what you want? I do not have the kde1d package to test the code.

library(kde1d)
library(ggplot2)
set.seed(100)
x=sample(1000,100)
fit <- kde1d(x,bw = 92)
Y <- pkde1d(x, fit)
DAT <- data.frame(X = x, Y = Y)
ggplot(DAT, aes(X, Y)) + geom_line(color = "black", size = 1.5) + 
  xlim(0,1000) + ylim(0,1) +
  labs(x = "Value", y = "Probability")
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.