|
|
|
||||
|
|
|||||
The examples here are created using R 2.6.2 for Windows XP. It uses the standard graphics package that R loads automatically when it starts.
set.seed(121343) u <- rnorm(100)
![]() |
#default histogram hist(u) |
![]() |
#with shading hist(u, density=20)
|
![]() |
#with specific number of bins hist(u, density=20, nclass=20)
|
![]() |
# proportion, instead of frequency
# also specifying y-axis
hist(u, density=20, breaks=-3:3,
ylim=c(0,.5), prob=TRUE)
|
![]() |
# overlay normal curve with x-lab and ylim
# colored normal curve
m<-mean(u)
std<-sqrt(var(u))
hist(u, density=20, nclass=15, prob=TRUE,
xlab="x-variable", ylim=c(0, 0.7),
main="normal curve over histogram")
curve(dnorm(x, mean=m, sd=std),
col="darkblue", lwd=2, add=TRUE)
|
![]() |
hist(u, density=20, nclass=15, prob=TRUE, xlab="x-variable", ylim=c(0, 0.8), main="normal curve over histogram") lines(density(u), col = "blue")
|
![]() |
# hist(u) is an object # names(uh) will show all of its components uh<-hist(u)
plot(uh, ylim=c(0, 40), col="lightgray",
xlab="", main="Histogram of u")
text(uh$mids, uh$counts+2, label=c(uh$counts))
|
UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services