-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathggplot.r
More file actions
executable file
·45 lines (33 loc) · 1.45 KB
/
ggplot.r
File metadata and controls
executable file
·45 lines (33 loc) · 1.45 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/Rscript
install.packages("ggplot2")
library(ggplot2)
# http://had.co.nz/ggplot2
# qplot examples -------------------------------------------------------------
qplot(diamonds$cut, diamonds$carat)
qplot(carat, price, data = diamonds)
qplot(carat, price, data = diamonds, colour=clarity)
qplot(carat, price, data = diamonds, geom=c("point", "smooth"), method=lm)
qplot(carat, data = diamonds,
 geom="histogram")
qplot(carat, data = diamonds,
 geom="histogram", binwidth = 1)
qplot(carat, data = diamonds,
 geom="histogram", binwidth = 0.1)
qplot(carat, data = diamonds,
 geom="histogram", binwidth = 0.01)
# using ggplot() -------------------------------------------------------------
d <- ggplot(diamonds, aes(x=carat, y=price))
d + geom_point()
d + geom_point(aes(colour = carat))
d + geom_point(aes(colour = carat)) + scale_colour_brewer()
ggplot(diamonds) + geom_histogram(aes(x=price))
# Separation of statistcs and geometric elements -----------------------------
p <- ggplot(diamonds, aes(x=price))
p + geom_histogram()
p + stat_bin(geom="area")
p + stat_bin(geom="point")
p + stat_bin(geom="line")
p + geom_histogram(aes(fill = clarity))
p + geom_histogram(aes(y = ..density..))
# Setting vs mapping ---------------------------------------------------------
p <- ggplot(diamonds, aes(x=carat,y=price))
# What will this do?
p + geom_point(aes(colour = "green"))
p + geom_point(colour = "green")
p + geom_point(colour = colour)