Statistics with R
- Statistics with R
- R Objects, Numbers, Attributes, Vectors, Coercion
- Matrices, Lists, Factors
- Data Frames in R
- Control Structures in R
- Functions in R
- Data Basics: Compute Summary Statistics in R
- Central Tendency and Spread in R Programming
- Data Basics: Plotting – Charts and Graphs
- Normal Distribution in R
- Skewness of statistical data
- Bernoulli Distribution in R
- Binomial Distribution in R Programming
- Compute Randomly Drawn Negative Binomial Density in R Programming
- Poisson Functions in R Programming
- How to Use the Multinomial Distribution in R
- Beta Distribution in R
- Chi-Square Distribution in R
- Exponential Distribution in R Programming
- Log Normal Distribution in R
- Continuous Uniform Distribution in R
- Understanding the t-distribution in R
- Gamma Distribution in R Programming
- How to Calculate Conditional Probability in R?
- How to Plot a Weibull Distribution in R
- Hypothesis Testing in R Programming
- T-Test in R Programming
- Type I Error in R
- Type II Error in R
- Confidence Intervals in R
- Covariance and Correlation in R
- Covariance Matrix in R
- Pearson Correlation in R
- Normal Probability Plot in R
How to Plot a Log Normal Distribution in R
To plot a log-normal distribution in R, you can use the dlnorm()
function to generate the probability density function (PDF) of the log-normal distribution, and then plot it using the plot()
function.
Here’s an example code that generates a log-normal distribution with a mean of 2 and a standard deviation of 1, and then plots it:
# Generate data for the log-normal distribution x <- seq(0.01, 10, length.out = 1000) mu <- 2 sigma <- 1 y <- dlnorm(x, meanlog = mu, sdlog = sigma) # Plot the log-normal distribution plot( x, y, type = "l", xlab = "x", ylab = "Density", main = "Log-Normal Distribution" )
In this code, seq(0.01, 10, length.out = 1000)
generates a sequence of 1000 equally spaced values from 0.01 to 10, which will be used as the x-axis values for the plot. meanlog
and sdlog
parameters of the dlnorm()
function specify the mean and standard deviation of the underlying normal distribution in the logarithmic scale. type = "l"
specifies that the plot should be a line plot, and xlab
, ylab
, and main
are used to set the axis labels and the plot title.
Example – 2
Here is an example code that generates a log-normal distribution with mean = 0 and standard deviation = 1, and plots the PDF:
# Set the mean and standard deviation mu <- 0 sigma <- 1 # Generate a sequence of x values x <- seq(from = 0.01, to = 10, by = 0.01) # Calculate the PDF using dlnorm() pdf <- dlnorm(x, meanlog = mu, sdlog = sigma) # Plot the PDF using plot() plot( x, pdf, type = "l", lwd = 2, xlab = "x", ylab = "PDF" )
This code generates a log-normal distribution with a mean of 0 and a standard deviation of 1, and plots the resulting PDF on the x-axis. The type = "l"
argument specifies that we want to plot a line graph, and lwd = 2
sets the line width to 2. The xlab
and ylab
arguments are used to label the x- and y-axes, respectively.
You can adjust the values of mu
and sigma
to create log-normal distributions with different means and standard deviations. You can also adjust the x
sequence to change the range and resolution of the x-axis.