Dateianhang 'skript5.r'
Herunterladen 1 require(ggplot2)
2 ## load the data set GaltonFamilies from the package HistData
3 require(HistData)
4
5 ## bivariate plots
6 ggplot(GaltonFamilies, aes(x=mother,y=father,size=children,shape=gender)) +
7 geom_point()
8
9
10 ggsave("scatter.png")
11
12 ## adding a trend line
13 ggplot(GaltonFamilies, aes(x=mother,y=father)) +
14 geom_point() +
15 geom_smooth()
16
17 ggsave("scattertrend1.png")
18
19
20 ## adding a trend line
21 ggplot(GaltonFamilies, aes(x=mother,y=father)) +
22 geom_point() +
23 geom_smooth(method="lm")
24
25 ggsave("scattertrend2.png")
26
27
28 ## Exercises
29 ## use again the GaltonFamilies data set; produce a scatter plot
30 ## of childHeight vs midparentHeight
31
32 ggplot(GaltonFamilies, aes(x=midparentHeight,y=childHeight)) +
33 geom_point()
34
35
36 ##add a trend line by using geom\_smooth() without any
37 ## arguments. Which method is used?
38 ggplot(GaltonFamilies, aes(x=midparentHeight,y=childHeight)) +
39 geom_point() +
40 geom_smooth()
41
42
43 ## add a second trend line, this time a linear one!
44 ggplot(GaltonFamilies, aes(x=midparentHeight,y=childHeight)) +
45 geom_point() +
46 geom_smooth(se=F,colour="red",size=3) +
47 geom_smooth(method="lm",se=F)
48
49
50 ## now use the aesthetic colour in the first line of the plot
51 ## definition. What happens?
52 ggplot(GaltonFamilies, aes(x=midparentHeight,y=childHeight,colour=gender)) +
53 geom_point() +
54 geom_smooth() +
55 geom_smooth(method="lm")
56
57
58 p1 <- ggplot(GaltonFamilies, aes(x=midparentHeight,y=childHeight,shape=gender)) +
59 geom_point() +
60 geom_smooth() +
61 geom_smooth(method="lm")
62
63 ## dot plots
64 ggplot(mtcars, aes(x = mpg)) + geom_dotplot()
65 ggsave("dotplot1.png")
66
67 ggplot(mtcars, aes(x = mpg)) + geom_dotplot(binwidth = 1.5)
68 ggsave("dotplot2.png")
69
70 ## Use fixed-width bins
71 ggplot(mtcars, aes(x = mpg)) +
72 geom_dotplot(method="histodot", binwidth = 1.5)
73 ggsave("dotplot3.png")
74
75 ## Some other stacking methods
76 ggplot(mtcars, aes(x = mpg)) +
77 geom_dotplot(binwidth = 1.5, stackdir = "center")
78 ggsave("dotplot4.png")
79
80 ## INBOtheme
81 install.packages("INBOtheme", repos="http://R-Forge.R-project.org")
82 require(INBOtheme)
83
84 p1 + theme_elsevier()
85 ggsave("testelsevier.png",width = 15, height = 10, units = "cm")
86
87 p1 + theme_INBO()
88 p1 + theme_map()
89 p1 + theme_inbo2015()
90
91
92 ## density legends
93 install.packages("oaPlots", repos = "http://repos.openanalytics.eu", type = "source")
94
95 require(oaPlots)
96 scatterplotDL(GaltonFamilies$mother,GaltonFamilies$childHeight,
97 colorVar = GaltonFamilies$childHeight,
98 colorPalette = blues9,
99 pch = 19)
100
101 scatterplotDL(GaltonFamilies$mother,GaltonFamilies$childHeight,
102 colorVar = GaltonFamilies$childHeight,
103 colorPalette = blues9,
104 pch = 19)
105
106 savePlot("legendexample.png")
107
108 ## membranes and tritiated water
109 data <- data.frame(values = c(0.8,0.83,1.89,1.04,1.45,
110 1.38,1.91,1.64,0.73,1.46,
111 1.15,0.88,0.9,0.74,1.21),
112 membrane = rep(LETTERS[1:2],c(10,5)))
113
114 ## histogram
115 ggplot(data,aes(x=values,colour=membrane)) +
116 geom_histogram() +
117 facet_wrap(~ membrane,nrow=2)
118
119 qqnorm(data$values[data$membrane=="A"])
120 qqline(data$values[data$membrane=="A"])
121
122 ## test
123 test <- wilcox.test(data$values ~ data$membrane, alternative = "greater")
124
125 ggplot(data,aes(x=values,fill=membrane)) +
126 geom_dotplot(binwidth = 0.1)
127
128 ggplot(data,aes(x=values,fill=membrane)) +
129 geom_dotplot(binwidth = 0.1) +
130 facet_wrap(~ membrane,nrow=2)
131
132 ggplot(data,aes(x=membrane,y=values)) +
133 geom_point(size=15,shape=21,fill="red")
134
135
136
137 ## weight loss programs
138
139 ## data
140 data <- data <- data.frame(x=c(12.42,9.31,6.83,11.51,10.42,8.87,6.73,9.53,8.8,8.01,7.01,9.69),
141 y=c(13.8,10,8.51,11.95,10.66,8.76,7.93,11.81,11.62,9.76,9.2,11.2))
142
143
144 ## investigate deviation from normality
145 ## histogram
146 dev.new()
147 hist(data$x - data$y)
148 ks.test(data$x - data$y,"pnorm",mean=mean(data$x - data$y))
149
150 ## test
151 t.test(data$y,data$x,paired = T)
152 t.test(data$y-data$x,mu=0)
153
154
155 ## visualization
156 require(granovaGG)
157 granovagg.ds(data,revc = T)
158
159
160 ## magnets
161
162 require(asbio)
163 data(magnets)
164 head(magnets)
165
166 ?magnets
167
168 magnets$diff <- magnets$Score_2 - magnets$Score_1
169
170 table(magnets$Active)
171
172 ggplot(magnets,aes(x=Active,y=diff)) +
173 geom_boxplot()
174
175
176 ggplot(magnets,aes(x=diff,fill=Active)) +
177 geom_dotplot(position = position_dodge(width=0.8),alpha=0.2)
178
179 ggplot(magnets,aes(x=diff,fill=Active)) +
180 geom_dotplot(alpha=0.2)
181
182
183 ggplot(magnets,aes(x=diff,fill=Active)) +
184 geom_histogram(position = position_dodge(width=0.8))
185
186 ggplot(magnets,aes(x=Active,y=diff)) +
187 geom_dotplot(binaxis = "y",stackdir = "center")
188
Gespeicherte Dateianhänge
Um Dateianhänge in eine Seite einzufügen sollte unbedingt eine Angabe wie attachment:dateiname benutzt werden, wie sie auch in der folgenden Liste der Dateien erscheint. Es sollte niemals die URL des Verweises ("laden") kopiert werden, da sich diese jederzeit ändern kann und damit der Verweis auf die Datei brechen würde.Sie dürfen keine Anhänge an diese Seite anhängen!