Dateianhang 'session5.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)) +
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
21 ## adding a trend line
22 ggplot(GaltonFamilies, aes(x=mother,y=father)) +
23 geom_point() +
24 geom_smooth(method="lm")
25
26 ggsave("scattertrend2.png")
27
28 ## dot plots
29 ggplot(mtcars, aes(x = mpg)) + geom_dotplot()
30 ggsave("dotplot1.png")
31
32 ggplot(mtcars, aes(x = mpg)) + geom_dotplot(binwidth = 1.5)
33 ggsave("dotplot2.png")
34
35 ## Use fixed-width bins
36 ggplot(mtcars, aes(x = mpg)) +
37 geom_dotplot(method="histodot", binwidth = 1.5)
38 ggsave("dotplot3.png")
39
40 ## Some other stacking methods
41 ggplot(mtcars, aes(x = mpg)) +
42 geom_dotplot(binwidth = 1.5, stackdir = "center")
43 ggsave("dotplot4.png")
44
45
46
47
48
49 ## Exercises
50 ## use again the GaltonFamilies data set; produce a scatter plot
51 ## of childHeight vs midparentHeight
52
53
54
55
56
57 ##add a trend line by using geom\_smooth() without any
58 ## arguments. Which method is used?
59
60
61
62 ## add a second trend line, this time a linear one!
63
64
65
66
67 ## now use the aesthetic colour in the first line of the plot
68 ## definition. What happens?
69
70
71
72
73
74
75 ## INBOtheme
76 install.packages("INBOtheme", repos="http://R-Forge.R-project.org")
77 require(INBOtheme)
78
79 p1 + theme_elsevier()
80 ggsave("testelsevier.png",width = 15, height = 10, units = "cm")
81
82 p1 + theme_INBO()
83 p1 + theme_map()
84 p1 + theme_inbo2015()
85
86
87 ## density legends
88 install.packages("oaPlots", repos = "http://repos.openanalytics.eu", type = "source")
89
90 require(oaPlots)
91 scatterplotDL(GaltonFamilies$mother,GaltonFamilies$childHeight,
92 colorVar = GaltonFamilies$childHeight,
93 colorPalette = INBOextra,
94 pch = 19)
95
96 scatterplotDL(GaltonFamilies$mother,GaltonFamilies$childHeight,
97 colorVar = GaltonFamilies$childHeight,
98 colorPalette = blues9,
99 pch = 19)
100
101 savePlot("legendexample.png")
102
103 ## membranes and tritiated water
104 data <- data.frame(values = c(0.8,0.83,1.89,1.04,1.45,
105 1.38,1.91,1.64,0.73,1.46,
106 1.15,0.88,0.9,0.74,1.21),
107 membrane = rep(LETTERS[1:2],c(10,5)))
108
109 ## histogram
110
111
112
113
114
115 ## test
116
117
118
119
120
121 ## weight loss programs
122
123 ## data
124 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),
125 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))
126
127
128 ## investigate deviation from normality
129 ## histogram
130
131
132 ## test
133
134
135
136 ## visualization
137
138
139
140 ## magnets (require(), data())
141
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!