This question already has answers here:
Fitting a density curve to a histogram in R
(7 answers)
Closed 4 years ago.
i would like to plot a histogram of a dataset and the plot of the fitting lognormal distribution - I only see the histogram and not the distribution function...
hist(kmugesamt, prob=TRUE)
curve(plnorm(x, mean=mean(kmugesamt), sd=sd(kmugesamt)), add=TRUE)
Many thanks in advance
Does this help?
k<-rlnorm(1000)
hist(k, freq=F)
curve(dlnorm(x, mean=mean(k), sd=sd(k)), add=TRUE)
Related
This question already has answers here:
How to plot a function curve in R
(7 answers)
R plot Probability Density Function
(1 answer)
Distributions and densities in R [duplicate]
(1 answer)
Closed 4 months ago.
I was trying to plot a probability density function curve in R for normal distribution. I have used the following codes but am not getting the normal curve shape in the graph. Anyone can help? This is the code.
#generating normal variables using R
x=rnorm(10,mean=0,sd=0.5)
x
y <- dnorm(rnorm(, mean = 0, sd = 0.5)
plot(x,y, type = "l")
This question already has answers here:
How to plot a function curve in R
(7 answers)
Closed 2 years ago.
How can I represent this function: y=-2*log(x) in a plot in R ? I am new to this programming language, any help will help. Thanks in advance.
You may try this.
y <- function(x) {-2*log(x)}
plot(y, 0, 1, ylab="y", xlab="x", lwd=2)
This question already has answers here:
Overlay normal curve to histogram in R
(4 answers)
Closed 4 years ago.
I am supposed to draw an overlay normal curve over a histogram in R. I am using the following code.
g <- unesco$Infant.Deaths
hist(g)
lines(seq(0, 200, by=5), dnorm(seq(0, 200, by=5),
mean(g), sd(g)), col="blue")
But instead of a curve, I am getting a straight line
It can be, that your histogram is representing frequencies instead of probability densities. Try to use hist(g, freq = FALSE).
This question already has an answer here:
Messy plot when plotting predictions of a polynomial regression using lm() in R
(1 answer)
Closed 5 years ago.
Here's how I plotted a quadratic curve:
factor <- 1:7
data <- c(0.1375000,0.2500000,0.3416667,0.4583333,0.7250000,0.9166667,1.0000000)
plot(factor, fitted(lm(data~factor+I(factor^2))), type="l")
I try to do the same with my another data.
factor1<-c(2833,2500,2437,2124,1382,3736,2100,1844,2740,957,1614,1100,1550,3858,2430,2139,1812,1757,1847,945)
data1<-c(0.95,0.88,0.88,0.93,0.81,0.67,0.55,0.53,0.52,0.90,0.87,0.20,0.28,-0.16,0.23,0.11,0.26,0.08,0.73,0.76)
plot(factor1,fitted(lm(data1~factor1+I(factor1^2))), type="l")
I think this is because the second dataset is not sorted but I thought R automatically sorts them before plotting them.
Could anyone tell me how to plot a quadratic line in the second plot.
You can order it first
i<-order(factor1)
plot(factor1[i],fitted(lm(data1[i]~factor1[i]+I(factor1[i]^2))), type="l")
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Fitting a density curve to a histogram in R
I'm trying to add a best fit normal over a histogram in R. Right now, I have the following:
x<-table[table$position==1,]$rt
hist(x,breaks=length(x))
And now I'd like to plot a normal curve over this plot which allows for skew and for kurtosis. How can I do this? This is what my curve looks like:
I would suggest not using the terms "skew" and "kurtosis" in the same sentence with "Normal curve", since Normal curves have neither. Perhaps you are looking for one or two parameter continuous density distribution that might be comparable to a function that was bounded at zero and had right skewing? If so then you should think about a) posting the data, b) consider plotting a Poisson, a log-Normal, or a gamma density on top of a histogram.
set.seed(123)
xpois <- trunc(rpois(100, 4))
hist(xpois)
lines(seq(0,10), 100*dpois(seq(0,10), 4))