forked from GreatKarollo/code_r
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdensity-plot.r
More file actions
25 lines (20 loc) · 747 Bytes
/
Copy pathdensity-plot.r
File metadata and controls
25 lines (20 loc) · 747 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Density Curve Plot
# Original source: r graphics cookbook
# load the gcookbook package for the data
library(gcookbook)
# load the ggplot2 package
library(ggplot2)
# reset the graphing device
dev.off()
# create the ggplot2 data for the faithful$waiting variable
ggplot(faithful, aes(x=waiting)) +
# add a sensity line
geom_line(stat="density") +
# zoom out the plot a little bit
expand_limits(y=0)
# create the ggplot2 data for three lines of different levels of smoothing
ggplot(faithful, aes(x=waiting)) +
# "adjust" determines the level of smoothing, larger the number, the more smoothing
geom_line(stat="density", adjust=.25, colour="red") +
geom_line(stat="density") +
geom_line(stat="density", adjust=2, colour="blue")