I want to plot an exponential distribution, something like this for example:
But I only know how to simulate a data frame that follow a exponential distribution and plot it.
data = data.frame(x=rexp(n = 100000, rate = .65))
m <- ggplot(data, aes(x=data$x))
m + geom_density()
From which I get:
How can I plot the true exponential distribution instead of a sampled version of the distribution?
The formula for the exponential distribution: P ( X = x ) = m e - m x = 1 μ e - 1 μ x P ( X = x ) = m e - m x = 1 μ e - 1 μ x Where m = the rate parameter, or μ = average time between occurrences.
The exponential distribution graph is a graph of the probability density function which shows the distribution of distance or time taken between events. The two terms used in the exponential distribution graph is lambda (λ)and x. Here, lambda represents the events per unit time and x represents the time.
To create an exponential curve, we can use exp function inside the plot function for the variable that we want to plot. For example, if we have a vector x then the exponential curve for the vector x can be created by using plot(x,exp(x)).
The exponential distribution can be obtained with the dexp
function, so you can plot it by sampling x
values and processing them with that function:
x <- seq(0, 20, length.out=1000)
dat <- data.frame(x=x, px=dexp(x, rate=0.65))
library(ggplot2)
ggplot(dat, aes(x=x, y=px)) + geom_line()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With