-
Notifications
You must be signed in to change notification settings - Fork 12
/
institute_olympics.R
107 lines (83 loc) · 4.09 KB
/
institute_olympics.R
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
dat <- data.frame(
names = c("FS","JC","MC","NDK","UK","CB","EM","HL","AW","PH","SZ","TJ","ED","GZ"),
height = c(185, 180, 170, 160, 155, 155, 155, 160, 170, 180, 185, 185, 178, 192),
weight = c( 95, 101, 101, 101, 95, 80, 68, 62, 62, 62, 68, 74, 74, 74),
age = c(18, 15, 10, 5, 2, 2, 2, 2, 5, 10, 15, 18, 18, 18),
memory = c(50, 60, 60, 60, 50, 40, 30, 20, 10, 10, 10, 20, 30, 50),
sib = c(0,0,0,0,0,0,0,0,0,1,2,3,3.4,4),
bfc = c(6,5,4.4,3,2.7,2,1,0,0,0,0,0,0,0),
inf = c( 6, 4, 2.5, 0, 0, 0, 0, 0, 3.1, 4, 6, 6, 6, 6),
dcs = c( 4e6, 5e6, 5e6, 5e6, 4e6, 3e6, 2e6, 1e6, 1e6, 1e6, 2e6, 3e6, 3.5e6, 4e6)
)
# blanks ####
g1 <- ggplot(dat, aes(x=height, y=weight)) + geom_blank() +
labs(x="Height", y="Weight") + opts(title="Figure 1") +
scale_x_continuous(limits=c(150,195), breaks=seq(145,195,5)) +
scale_y_continuous(breaks=seq(60,100,5))
g2 <- ggplot(dat, aes(x=age, y=memory)) + geom_blank() +
labs(x="Age", y="Memory (Verbal)") + opts(title="Figure 2") +
scale_x_continuous(limits=c(0,20), breaks=seq(0,20,2)) +
scale_y_continuous(breaks=seq(5,65,5))
g3 <- ggplot(dat, aes(x=sib, y=bfc)) + geom_blank() +
labs(x="No. Siblings", y="No. Bone Fractures") + opts(title="Figure 3") +
scale_x_continuous(limits=c(-0.5,4.5), breaks=seq(0,4,1))
g4 <- ggplot(dat, aes(x=inf, y=dcs)) + geom_blank() +
labs(x="No. Previous Infections", y="No. Dendric Cells") + opts(title="Figure 4") +
scale_x_continuous( limits=c(-0.5,6.5), breaks=seq(0,6,1))
png(paste0(Sys.Date(),"_blank_plain.png"), units="in", width=14, height=4, res=300)
grid.arrange(g1,g2,g3,g4, ncol=4, clip=T)
dev.off()
# with points ####
g1 <- g1 + geom_point()
g2 <- g2 + geom_point()
g3 <- g3 + geom_point()
g4 <- g4 + geom_point()
png(paste0(Sys.Date(),"_points_plain.png"), units="in", width=14, height=4, res=300)
grid.arrange(g1,g2,g3,g4, ncol=4, clip=T)
dev.off()
# with paths ####
g1 <- g1 + geom_path(size=1.5) + geom_point(colour="red",size=3.5)
g2 <- g2 + geom_path(size=1.5) + geom_point(colour="red",size=3.5)
g3 <- g3 + geom_path(size=1.5) + geom_point(colour="red",size=3.5)
g4 <- g4 + geom_path(size=1.5) + geom_point(colour="red",size=3.5)
png(paste0(Sys.Date(),"_points_path_plain.png"), units="in", width=14, height=4, res=300)
grid.arrange(g1,g2,g3,g4, ncol=4, clip=T)
dev.off()
dat
# jittering ####
set.seed(1234)
dat[,2:9] <- apply(dat[,2:9],2, function(x) round(jitter(x),1))
# blanks ####
g1 <- ggplot(dat, aes(x=height, y=weight)) + geom_blank() +
labs(x="Height", y="Weight") + opts(title="Figure 1") +
scale_x_continuous(limits=c(150,195), breaks=seq(145,195,5)) +
scale_y_continuous(breaks=seq(60,100,5))
g2 <- ggplot(dat, aes(x=age, y=memory)) + geom_blank() +
labs(x="Age", y="Memory (Verbal)") + opts(title="Figure 2") +
scale_x_continuous(limits=c(0,20), breaks=seq(0,20,2)) +
scale_y_continuous(breaks=seq(5,65,5))
g3 <- ggplot(dat, aes(x=sib, y=bfc)) + geom_blank() +
labs(x="No. Siblings", y="No. Bone Fractures") + opts(title="Figure 3") +
scale_x_continuous(limits=c(-0.5,4.5), breaks=seq(0,4,1))
g4 <- ggplot(dat, aes(x=inf, y=dcs)) + geom_blank() +
labs(x="No. Previous Infections", y="No. Dendric Cells") + opts(title="Figure 4") +
scale_x_continuous( limits=c(-0.5,6.5), breaks=seq(0,6,1))
png(paste0(Sys.Date(),"_blank_jitter.png"), units="in", width=14, height=4, res=300)
grid.arrange(g1,g2,g3,g4, ncol=4, clip=T)
dev.off()
# with points ####
g1 <- g1 + geom_point()
g2 <- g2 + geom_point()
g3 <- g3 + geom_point()
g4 <- g4 + geom_point()
png(paste0(Sys.Date(),"_points_jitter.png"), units="in", width=14, height=4, res=300)
grid.arrange(g1,g2,g3,g4, ncol=4, clip=T)
dev.off()
# with paths ####
g1 <- g1 + geom_path(size=1.5) + geom_point(colour="red",size=3.5)
g2 <- g2 + geom_path(size=1.5) + geom_point(colour="red",size=3.5)
g3 <- g3 + geom_path(size=1.5) + geom_point(colour="red",size=3.5)
g4 <- g4 + geom_path(size=1.5) + geom_point(colour="red",size=3.5)
png(paste0(Sys.Date(),"_points_path_jitter.png"), units="in", width=14, height=4, res=300)
grid.arrange(g1,g2,g3,g4, ncol=4, clip=T)
dev.off()