-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.Rhistory
322 lines (322 loc) · 17.1 KB
/
.Rhistory
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
R.version
glimpse(penguins)
#Load Palmer Penguin library and data set
library(palmerpenguins)
data(package = 'palmerpenguins')
#Load libraries we need for dataframe manipulation and plotting
library(tidyr)
library(dplyr)
library(ggplot2)
library(gridExtra)
glimpse(penguins)
str(penguins)
#Initial plot to see which parameters might yield clues about species types
#Species vs flipper length
ggplot(aes(x = species, y = flipper_length_mm), data = df) + geom_boxplot() +
stat_summary(fun = mean, geom = 'point', shape = 4)
#Copy data into new datafrme and look at Column names for calculations
df <- penguins
names(df)
#Initial plot to see which parameters might yield clues about species types
#Species vs body mass
ggplot(aes(x = species, y = body_mass_g), data = df) + geom_boxplot() +
stat_summary(fun = mean, geom = 'point', shape = 4)
#Initial plot to see which parameters might yield clues about species types
#Species vs bill length
ggplot(aes(x = species, y = bill_length_mm), data = df) + geom_boxplot() +
stat_summary(fun = mean, geom = 'point', shape = 4)
#Initial plot to see which parameters might yield clues about species types
#Species vs bill depth
ggplot(aes(x = species, y = bill_depth_mm), data = df) + geom_boxplot() +
stat_summary(fun = mean, geom = 'point', shape = 4)
#Initial plot to see which parameters might yield clues about species types
#Species vs flipper length
ggplot(aes(x = species, y = flipper_length_mm), data = df) + geom_boxplot() +
stat_summary(fun = mean, geom = 'point', shape = 4)
visdat::vis_dat(penguins)
ggplot(penguins, aes(x = island, fill = species)) +
geom_bar(alpha = 0.8) +
scale_fill_manual(values = c("darkorange","purple","cyan4"),
guide = FALSE) +
theme_minimal() +
facet_wrap(~species, ncol = 1) +
coord_flip()
penguins %>%
select(species, body_mass_g, ends_with("_mm")) %>%
GGally::ggpairs(aes(color = species)) +
scale_colour_manual(values = c("darkorange","purple","cyan4")) +
scale_fill_manual(values = c("darkorange","purple","cyan4"))
#Initial plot to see which parameters might yield clues about species types
#Species vs body mass
ggplot(aes(x = species, y = body_mass_g), data = df) + geom_boxplot() +
stat_summary(fun = mean, geom = 'point', shape = 4) +
scale_colour_manual(values = c("darkorange","purple","cyan4")) +
scale_fill_manual(values = c("darkorange","purple","cyan4"))
#Initial plot to see which parameters might yield clues about species types
#Species vs body mass
ggplot(aes(x = species, y = body_mass_g), data = df) + geom_boxplot(color='darkblue') +
stat_summary(fun = mean, geom = 'point', shape = 4)
#Initial plot to see which parameters might yield clues about species types
#Species vs body mass
ggplot(aes(x = species, y = body_mass_g, color=cyl), data = df) + geom_boxplot(color='darkblue') +
stat_summary(fun = mean, geom = 'point', shape = 4)
#Initial plot to see which parameters might yield clues about species types
#Species vs body mass
ggplot(aes(x = species, y = body_mass_g, color=species), data = df) + geom_boxplot(color='darkblue') +
stat_summary(fun = mean, geom = 'point', shape = 4)
#Initial plot to see which parameters might yield clues about species types
#Species vs body mass
ggplot(aes(x = species, y = body_mass_g, color=species), data = df) + geom_boxplot(color=species) +
stat_summary(fun = mean, geom = 'point', shape = 4)
#Initial plot to see which parameters might yield clues about species types
#Species vs body mass
ggplot(aes(x = species, y = body_mass_g, color=species), data = df) + geom_boxplot(color="species"blue) +
#Initial plot to see which parameters might yield clues about species types
#Species vs body mass
ggplot(aes(x = species, y = body_mass_g, color=species), data = df) + geom_boxplot(color="species"blue") +
#Initial plot to see which parameters might yield clues about species types
#Species vs body mass
ggplot(aes(x = species, y = body_mass_g, color=species), data = df) + geom_boxplot(color="blue") +
stat_summary(fun = mean, geom = 'point', shape = 4)
#Initial plot to see which parameters might yield clues about species types
#Species vs body mass
ggplot(aes(x = species, y = body_mass_g, color=species), data = df) + geom_boxplot(color="blue") +
stat_summary(fun = mean, geom = 'point', shape = 4) + scale_fill_hue(l=40, c=35)
#Initial plot to see which parameters might yield clues about species types
#Species vs body mass
ggplot(aes(x = species, y = body_mass_g, color=species), data = df) + geom_boxplot(color="blue") +
stat_summary(fun = mean, geom = 'point', shape = 4)
#Initial plot to see which parameters might yield clues about species types
#Species vs body mass
ggplot(aes(x = species, y = body_mass_g), data = df) + geom_boxplot() +
stat_summary(fun = mean, geom = 'point', shape = 4)
#Initial plot to see which parameters might yield clues about species types
#Species vs body mass
ggplot(aes(x = species, y = body_mass_g), data = df) + geom_boxplot() +
stat_summary(fun = mean, geom = 'point', shape = 4)
#Initial plot to see which parameters might yield clues about species types
#Species vs body mass
ggplot(aes(x = species, y = body_mass_g), data = df) + scale_fill_manual(values=c("#999999", "#E69F00", "#56B4E9")) + geom_boxplot() +
stat_summary(fun = mean, geom = 'point', shape = 4)
#Initial plot to see which parameters might yield clues about species types
#Species vs body mass
ggplot(aes(x = species, y = body_mass_g), data = df) + geom_boxplot() + + scale_fill_manual(values=c("#999999", "#E69F00", "#56B4E9"))+
stat_summary(fun = mean, geom = 'point', shape = 4)
#Initial plot to see which parameters might yield clues about species types
#Species vs body mass
ggplot(aes(x = species, y = body_mass_g), data = df) + geom_boxplot() + scale_fill_manual(values=c("#999999", "#E69F00", "#56B4E9"))+
stat_summary(fun = mean, geom = 'point', shape = 4)
#Initial plot to see which parameters might yield clues about species types
#Species vs body mass
ggplot(aes(x = species, y = body_mass_g), data = df) + geom_boxplot() +
stat_summary(fun = mean, geom = 'point', shape = 4)
#Initial plot to see which parameters might yield clues about species types
#Species vs body mass
ggplot(aes(x = species, y = body_mass_g), data = df)
#Initial plot to see which parameters might yield clues about species types
#Species vs body mass
ggplot(aes(x = species, y = body_mass_g), data = df) + geom_boxplot()
#Initial plot to see which parameters might yield clues about species types
#Species vs body mass
ggplot(aes(x = species, y = body_mass_g), data = df) + geom_boxplot(fill='#A4A4A4', color="darkred")
#Initial plot to see which parameters might yield clues about species types
#Species vs body mass
ggplot(aes(x = species, y = body_mass_g), data = df) + geom_boxplot(fill='#ffffff', color="darkred")
#Initial plot to see which parameters might yield clues about species types
#Species vs body mass
ggplot(aes(x = species, y = body_mass_g), data = df) + geom_boxplot(fill='#fffff', color="darkred")
#Initial plot to see which parameters might yield clues about species types
#Species vs body mass
ggplot(aes(x = species, y = body_mass_g), data = df) + geom_boxplot(fill='#fffff3', color="darkred")
#Initial plot to see which parameters might yield clues about species types
#Species vs body mass
ggplot(aes(x = species, y = body_mass_g), data = df) + geom_boxplot(fill='darkblue', color="darkred")
#Initial plot to see which parameters might yield clues about species types
#Species vs body mass
ggplot(aes(x = species, y = body_mass_g), data = df) + geom_boxplot() + scale_fill_hue(l=40, c=35)
#Initial plot to see which parameters might yield clues about species types
#Species vs body mass
bp <- ggplot(aes(x = species, y = body_mass_g), data = df) + geom_boxplot()
bp + scale_fill_hue(l=40, c=35)
#Initial plot to see which parameters might yield clues about species types
#Species vs body mass
bp<-ggplot(aes(x = species, y = body_mass_g), data = df) + geom_boxplot()
bp + scale_fill_hue(l=40, c=35)
#Initial plot to see which parameters might yield clues about species types
#Species vs body mass
bp<-ggplot(aes(x = species, y = body_mass_g, fill=dose), data = df) + geom_boxplot()
bp + scale_fill_hue(l=40, c=35)
#Initial plot to see which parameters might yield clues about species types
#Species vs body mass
bp<-ggplot(aes(x = species, y = body_mass_g, fill=species), data = df) + geom_boxplot()
bp + scale_fill_hue(l=40, c=35)
#Initial plot to see which parameters might yield clues about species types
#Species vs body mass
bp<-ggplot(aes(x = species, y = body_mass_g, fill=species), data = df) + geom_boxplot() + coord_flip()
bp + scale_fill_hue(l=40, c=35)
#Initial plot to see which parameters might yield clues about species types
#Species vs bill length
bp<-ggplot(aes(x = species, y = bill_length_rm, fill=species), data = df) + geom_boxplot() + coord_flip()
bp + scale_fill_hue(l=40, c=35)
#Initial plot to see which parameters might yield clues about species types
#Species vs bill length
bp<-ggplot(aes(x = species, y = bill_length_mm, fill=species), data = df) + geom_boxplot() + coord_flip()
bp + scale_fill_hue(l=40, c=35)
#Initial plot to see which parameters might yield clues about species types
#Species vs bill depth
bp<-ggplot(aes(x = species, y = bill_depth_mm, fill=species), data = df) + geom_boxplot() + coord_flip()
bp + scale_fill_hue(l=40, c=35)
#Initial plot to see which parameters might yield clues about species types
#Species vs flipper length
bp<-ggplot(aes(x = species, y = flipper_length_mm, fill=species), data = df) + geom_boxplot() + coord_flip()
bp + scale_fill_hue(l=40, c=35)
#Grid analysis of histograms of the parameers: Lengt and Width and the Petal Length and Width.
# "species" "island" "bill_length_mm" "bill_depth_mm" "flipper_length_mm"
# "body_mass_g" "sex" "year"
p1 <- ggplot(aes(x = bill_length_mm, fill = species), data = df) +
geom_histogram()
p2 <- ggplot(aes(x = bill_depth_mm, fill = species), data = df) +
geom_histogram()
p3 <- ggplot(aes(x = flipper_length_mm, fill = species), data = df) + geom_histogram()
p4 <- ggplot(aes(x = body_mass_g, fill = species), data = df) +
geom_histogram()
grid.arrange(p1, p2, p3, p4, ncol = 2)
#Examine penguin data set with pairs matrix
pairs(penguins, col=penguins$species) +
scale_colour_manual(values = c("darkorange","purple","cyan4")) +
scale_fill_manual(values = c("darkorange","purple","cyan4"))
#Examine penguin data set with pairs matrix
pairs(penguins, col=penguins$species)
data_for_clustering <- df[,-5]
#kmeans data clustering partitioning (assuming 3 centers or clusters).
clusters_penguins <- kmeans(data_for_clustering, centers = 3)
data_for_clustering <- df
#kmeans data clustering partitioning (assuming 3 centers or clusters).
clusters_penguins <- kmeans(data_for_clustering, centers = 3, iter.max = 10, nstart = 1)
data_for_clustering <- df %>% drop_na()
#kmeans data clustering partitioning (assuming 3 centers or clusters).
clusters_penguins <- kmeans(data_for_clustering, centers = 3, iter.max = 10, nstart = 1)
data_for_clustering <- df
data_for_clustinerg %>% drop_na()
data_for_clustering <- df
data_for_clustering %>% drop_na()
#kmeans data clustering partitioning (assuming 3 centers or clusters).
clusters_penguins <- kmeans(data_for_clustering, centers = 3, iter.max = 10, nstart = 1)
data_for_clustering <- df
data_for_clustering %>% drop_na()
#kmeans data clustering partitioning (assuming 3 centers or clusters).
clusters_penguins <- kmeans(data_for_clustering, centers = 3)
data_for_clustering <- df[,3:6]
data_for_clustering %>% drop_na()
#kmeans data clustering partitioning (assuming 3 centers or clusters).
clusters_penguins <- kmeans(data_for_clustering, centers = 3)
data_for_clustering <- df[,3:6]
data_for_clustering %>% drop_na()
#kmeans data clustering partitioning (assuming 3 centers or clusters).
data_for_clustering
data_for_clustering <- df[,3:6]
data_for_clustering[!is.na(), ]
data_for_clustering <- df[,3:6]
data_for_clustering[!is.na(data_for_clustering), ]
data_for_clustering <- df[,3:6]
data_for_clustering
#kmeans data clustering partitioning (assuming 3 centers or clusters).
#data_for_clustering
data_for_clustering <- df[,3:6]
data_for_clustering_no_na <- drop_na(data_for_clustering)
#kmeans data clustering partitioning (assuming 3 centers or clusters).
data_for_clustering_no_na
data_for_clustering <- df[,3:6]
data_for_clustering_no_na <- drop_na(data_for_clustering)
#kmeans data clustering partitioning (assuming 3 centers or clusters).
data_for_clustering_no_na
clusters <- kmeans(data_for_clustering_no_na, 3)
clusters
library(cluster)
library(fpc)
library(factoextra)
library(knitr)
data_for_clustering <- df[,3:6]
data_for_clustering_no_na <- drop_na(data_for_clustering)
#kmeans data clustering partitioning (assuming 3 centers or clusters).
data_for_clustering_no_na
clusters_penguins <- kmeans(data_for_clustering_no_na, 3)
plotcluster(data_for_clustering_no_na,clusters_penguins$cluster)
plotcluster(data_for_clustering_no_na,clusters_penguins$cluster, color = TRUE, shade = TRUE)
data_for_clustering <- df[,3:6]
data_for_clustering_no_na <- drop_na(data_for_clustering)
#kmeans data clustering partitioning (assuming 3 centers or clusters).
data_for_clustering_no_na
clusters_penguins <- kmeans(data_for_clustering_no_na, iter.max = 10, nstart = 1)
data_for_clustering <- df[,3:6]
data_for_clustering_no_na <- drop_na(data_for_clustering)
#kmeans data clustering partitioning (assuming 3 centers or clusters).
data_for_clustering_no_na
clusters_penguins <- kmeans(data_for_clustering_no_na, iter.max = 10, nstart = 25)
data_for_clustering <- df[,3:6]
data_for_clustering_no_na <- drop_na(data_for_clustering)
#kmeans data clustering partitioning (assuming 3 centers or clusters).
data_for_clustering_no_na
clusters_penguins <- kmeans(data_for_clustering_no_na, iter.max = 10, nstart = 25, centers = 5)
plotcluster(data_for_clustering_no_na,clusters_penguins$cluster, color = TRUE, shade = TRUE)
data_for_clustering <- df[,3:6]
data_for_clustering_no_na <- drop_na(data_for_clustering)
#kmeans data clustering partitioning (assuming 3 centers or clusters).
data_for_clustering_no_na
clusters_penguins <- kmeans(data_for_clustering_no_na, iter.max = 10, nstart = 25, centers = 4)
plotcluster(data_for_clustering_no_na,clusters_penguins$cluster, color = TRUE, shade = TRUE)
data_for_clustering <- df[,3:6]
data_for_clustering_no_na <- drop_na(data_for_clustering)
#kmeans data clustering partitioning (assuming 3 centers or clusters).
data_for_clustering_no_na
clusters_penguins <- kmeans(data_for_clustering_no_na, iter.max = 10, nstart = 25, centers = 3)
plotcluster(data_for_clustering_no_na,clusters_penguins$cluster, color = TRUE, shade = TRUE)
table(clusters_penguins$cluster, penguins$species)
set.seed(20)
data_for_clustering <- df
data_for_clustering_no_na <- drop_na(data_for_clustering)
#kmeans data clustering partitioning (assuming 3 centers or clusters).
clusters_penguins <- kmeans(data_for_clustering_no_na[,3:6], nstart = 20, centers = 3)
plotcluster(data_for_clustering_no_na,clusters_penguins$cluster, color = TRUE, shade = TRUE)
set.seed(20)
data_for_clustering <- df
data_for_clustering_no_na <- drop_na(data_for_clustering)
#kmeans data clustering partitioning (assuming 3 centers or clusters).
clusters_penguins <- kmeans(data_for_clustering_no_na[,3:6], nstart = 20, centers = 3)
plotcluster(data_for_clustering_no_na[,3:6], clusters_penguins$cluster, color = TRUE, shade = TRUE)
table(clusters_penguins$cluster, penguins$species)
clusters_penguins
table(clusters_penguins)
set.seed(20)
data_for_clustering <- df
data_for_clustering_no_na <- drop_na(data_for_clustering)
#kmeans data clustering partitioning (assuming 3 centers or clusters).
clusters_penguins <- kmeans(data_for_clustering_no_na[,3:6], nstart = 20, centers = 3)
plotcluster(data_for_clustering_no_na[,3:6], clusters_penguins$cluster, color = TRUE, shade = TRUE)
penguins_no_na <- drop_na(penguins)
table(clusters_penguins$cluster, penguins_no_na$species)
set.seed(20)
data_for_clustering <- df
data_for_clustering_no_na <- drop_na(data_for_clustering)
#kmeans data clustering partitioning (assuming 3 centers or clusters).
clusters_penguins <- kmeans(data_for_clustering_no_na[,3:6], nstart = 20, centers = 4)
plotcluster(data_for_clustering_no_na[,3:6], clusters_penguins$cluster, color = TRUE, shade = TRUE)
penguins_no_na <- drop_na(penguins)
table(clusters_penguins$cluster, penguins_no_na$species)
set.seed(20)
data_for_clustering <- df
data_for_clustering_no_na <- drop_na(data_for_clustering)
#kmeans data clustering partitioning (assuming 3 centers or clusters).
clusters_penguins <- kmeans(data_for_clustering_no_na[,3:6], nstart = 20, centers = 2)
plotcluster(data_for_clustering_no_na[,3:6], clusters_penguins$cluster, color = TRUE, shade = TRUE)
penguins_no_na <- drop_na(penguins)
table(clusters_penguins$cluster, penguins_no_na$species)
#Variables used in clustering "bill_length_mm" "bill_depth_mm" "flipper_length_mm" "body_mass_g"
set.seed(20)
data_for_clustering <- df
data_for_clustering_no_na <- drop_na(data_for_clustering)
#kmeans data clustering partitioning (assuming 3 centers or clusters).
clusters_penguins <- kmeans(data_for_clustering_no_na[,3:6], nstart = 20, centers = 3)
plotcluster(data_for_clustering_no_na[,3:6], clusters_penguins$cluster, color = TRUE, shade = TRUE)
penguins_no_na <- drop_na(penguins)
table(clusters_penguins$cluster, penguins_no_na$species)