# wget https://raw.githubusercontent.com/dhavalpotdar/College-Scorecard-Data-Analysis/master/MERGED_2017_2018_cleaned.csv--2024-04-16 18:46:06-- https://raw.githubusercontent.com/dhavalpotdar/College-Scorecard-Data-Analysis/master/MERGED_2017_2018_cleaned.csv
# mv MERGED_2017_2018_cleaned.csv college_score.csv
# sed -n '10,60p' college_score.csv
# awk -F, '{if ($8=="Public" && $3=="Montgomery") {print}}' college_score.csv > subsample.csv
# For subsample.csv :
# awk -F, '{print$3}' subsample.csv | sort | uniq -c
# For college_score.csv
# awk -F, '{print$3}' college_score.csv | sort | uniq -c | sort -n
chocolate <- read.csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2022/2022-01-18/chocolate.csv")
head(chocolate)
## ref company_manufacturer company_location review_date country_of_bean_origin
## 1 2454 5150 U.S.A. 2019 Tanzania
## 2 2458 5150 U.S.A. 2019 Dominican Republic
## 3 2454 5150 U.S.A. 2019 Madagascar
## 4 2542 5150 U.S.A. 2021 Fiji
## 5 2546 5150 U.S.A. 2021 Venezuela
## 6 2546 5150 U.S.A. 2021 Uganda
## specific_bean_origin_or_bar_name cocoa_percent ingredients
## 1 Kokoa Kamili, batch 1 76% 3- B,S,C
## 2 Zorzal, batch 1 76% 3- B,S,C
## 3 Bejofo Estate, batch 1 76% 3- B,S,C
## 4 Matasawalevu, batch 1 68% 3- B,S,C
## 5 Sur del Lago, batch 1 72% 3- B,S,C
## 6 Semuliki Forest, batch 1 80% 3- B,S,C
## most_memorable_characteristics rating
## 1 rich cocoa, fatty, bready 3.25
## 2 cocoa, vegetal, savory 3.50
## 3 cocoa, blackberry, full body 3.75
## 4 chewy, off, rubbery 3.00
## 5 fatty, earthy, moss, nutty,chalky 3.00
## 6 mildly bitter, basic cocoa, fatty 3.25
str(chocolate)
## 'data.frame': 2530 obs. of 10 variables:
## $ ref : int 2454 2458 2454 2542 2546 2546 2542 797 797 1011 ...
## $ company_manufacturer : chr "5150" "5150" "5150" "5150" ...
## $ company_location : chr "U.S.A." "U.S.A." "U.S.A." "U.S.A." ...
## $ review_date : int 2019 2019 2019 2021 2021 2021 2021 2012 2012 2013 ...
## $ country_of_bean_origin : chr "Tanzania" "Dominican Republic" "Madagascar" "Fiji" ...
## $ specific_bean_origin_or_bar_name: chr "Kokoa Kamili, batch 1" "Zorzal, batch 1" "Bejofo Estate, batch 1" "Matasawalevu, batch 1" ...
## $ cocoa_percent : chr "76%" "76%" "76%" "68%" ...
## $ ingredients : chr "3- B,S,C" "3- B,S,C" "3- B,S,C" "3- B,S,C" ...
## $ most_memorable_characteristics : chr "rich cocoa, fatty, bready" "cocoa, vegetal, savory" "cocoa, blackberry, full body" "chewy, off, rubbery" ...
## $ rating : num 3.25 3.5 3.75 3 3 3.25 3.5 3.5 3.75 2.75 ...
comment: The data frame has 2530 observations and 10 variables total , which consists of 2 integer, 7 character and 1 numeric.
chocolate <- chocolate %>%
mutate_if(is.character, as.factor)
str(chocolate)
## 'data.frame': 2530 obs. of 10 variables:
## $ ref : int 2454 2458 2454 2542 2546 2546 2542 797 797 1011 ...
## $ company_manufacturer : Factor w/ 580 levels "5150","A. Morin",..: 1 1 1 1 1 1 1 2 2 2 ...
## $ company_location : Factor w/ 67 levels "Amsterdam","Argentina",..: 63 63 63 63 63 63 63 19 19 19 ...
## $ review_date : int 2019 2019 2019 2021 2021 2021 2021 2012 2012 2013 ...
## $ country_of_bean_origin : Factor w/ 62 levels "Australia","Belize",..: 53 13 29 17 61 59 24 4 37 35 ...
## $ specific_bean_origin_or_bar_name: Factor w/ 1605 levels "\"Classic Dark\", Ecuador-Guatemala-Dom. Rep.",..: 744 1603 163 938 1420 1366 82 208 1141 1117 ...
## $ cocoa_percent : Factor w/ 46 levels "100%","42%","46%",..: 30 30 30 19 25 34 19 21 14 21 ...
## $ ingredients : Factor w/ 22 levels "","1- B","2- B,C",..: 6 6 6 6 6 6 6 11 11 11 ...
## $ most_memorable_characteristics : Factor w/ 2487 levels "accesible, simple cocoa note",..: 1678 316 285 226 740 1329 1333 2429 887 124 ...
## $ rating : num 3.25 3.5 3.75 3 3 3.25 3.5 3.5 3.75 2.75 ...
chocolate %>%
group_by(company_location) %>%
reframe(mean = mean(rating),
std = sd(rating),
median = median(rating),
min = min(rating), max = max(rating))
## # A tibble: 67 × 6
## company_location mean std median min max
## <fct> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 Amsterdam 3.31 0.264 3.25 3 3.75
## 2 Argentina 3.31 0.349 3.5 2.75 3.75
## 3 Australia 3.36 0.409 3.5 2.5 4
## 4 Austria 3.26 0.325 3.25 2.75 3.75
## 5 Belgium 3.10 0.661 3 1 4
## 6 Bolivia 3.25 0.707 3.25 2.75 3.75
## 7 Brazil 3.28 0.356 3.25 2.5 4
## 8 Canada 3.30 0.416 3.25 2 4
## 9 Chile 3.75 0 3.75 3.75 3.75
## 10 Colombia 3.20 0.425 3.25 2 3.75
## # ℹ 57 more rows
comment: We can observe from the first ten
observations that Australia has the highest mean rating while Belgium is
the lowest. For all countries, medians close to each other, and it can
be seen that Chile has the same mean, median, min and max
moreover its standard deviation is zero so all the observations have the
value 3.75.
chocolate %>%
filter(review_date==2020 & country_of_bean_origin=="Colombia")
## ref company_manufacturer company_location review_date country_of_bean_origin
## 1 2466 Crow and Moss U.S.A. 2020 Colombia
## 2 2534 El Buen U.S.A. 2020 Colombia
## 3 2482 Finnia Canada 2020 Colombia
## 4 2478 Kin + Pod Canada 2020 Colombia
## 5 2498 Odyssey U.S.A. 2020 Colombia
## specific_bean_origin_or_bar_name cocoa_percent ingredients
## 1 Aruaca, batch 39 70% 2- B,S
## 2 Tumaco 70% 2- B,S
## 3 Chigorodo, batch 001 70% 3- B,S,C
## 4 Tumaco, batch 113 70% 3- B,S,C
## 5 Arhuaca 70% 2- B,S
## most_memorable_characteristics rating
## 1 nutty, citrus 3.25
## 2 cocoa, spice, alcohol, dirty 3.00
## 3 nutty, melon, vinegar 2.75
## 4 poor finish, cocoa, grassy 3.25
## 5 walnut, tobacco, grassy 3.25
First, we need to change the class of the cocoa_percent.
chocolate$cocoa_percent <- gsub("%", "", chocolate$cocoa_percent)
chocolate$cocoa_percent <- as.numeric(chocolate$cocoa_percent)
class(chocolate$cocoa_percent)
## [1] "numeric"
chocolate %>%
subset(., select=c(company_location, rating, cocoa_percent)) %>%
aggregate(cbind(rating, cocoa_percent)~company_location, ., mean) %>%
head()
## company_location rating cocoa_percent
## 1 Amsterdam 3.312500 70.75000
## 2 Argentina 3.305556 73.33333
## 3 Australia 3.358491 70.18868
## 4 Austria 3.258333 72.13333
## 5 Belgium 3.103175 72.14286
## 6 Bolivia 3.250000 73.00000
library(dplyr)
chocolate %>%
select(starts_with("co")) %>%
select(-cocoa_percent) %>%
head(10)
## company_manufacturer company_location country_of_bean_origin
## 1 5150 U.S.A. Tanzania
## 2 5150 U.S.A. Dominican Republic
## 3 5150 U.S.A. Madagascar
## 4 5150 U.S.A. Fiji
## 5 5150 U.S.A. Venezuela
## 6 5150 U.S.A. Uganda
## 7 5150 U.S.A. India
## 8 A. Morin France Bolivia
## 9 A. Morin France Peru
## 10 A. Morin France Panama
library(dplyr)
chocolate %>%
filter(company_location=="Switzerland" & 2.5<rating & rating<3.5) %>%
head(5)
## ref company_manufacturer company_location review_date country_of_bean_origin
## 1 508 Beschle (Felchlin) Switzerland 2010 Venezuela
## 2 508 Beschle (Felchlin) Switzerland 2010 Venezuela
## 3 636 Beschle (Felchlin) Switzerland 2011 Madagascar
## 4 636 Beschle (Felchlin) Switzerland 2011 Venezuela
## 5 2230 Cacao Betulia Switzerland 2018 Colombia
## specific_bean_origin_or_bar_name cocoa_percent ingredients
## 1 Carenero S., Barlovento, Grand Cru 70 3- B,S,C
## 2 Porcelana, Premier Cru, Quizas No. 1 74 3- B,S,C
## 3 Madagascar 64 3- B,S,C
## 4 Maracaibo 88 3- B,S,C
## 5 H. Betulia, Antioquia, B9 72 2- B,S
## most_memorable_characteristics rating
## 1 creamy, macadamia, pepper 3.25
## 2 nutty, light toffee, mild musty 3.25
## 3 chunky, nutty, banana 3.00
## 4 bitter then nutty rustic, earthy 3.00
## 5 light color, dirty, astringent 3.00
Note : As an easier alternative
chocolate %>% filter(company_location=="Switzerland" & between(rating, 3.25, 3.5)) %>% head(5)
chocolate %>%
subset(., select = c(company_location, rating)) %>%
aggregate(rating ~ company_location, ., mean) %$%
.[order(rating, decreasing = T),] %>%
head()
## company_location rating
## 9 Chile 3.750000
## 61 U.A.E. 3.400000
## 43 Poland 3.375000
## 66 Vietnam 3.359375
## 3 Australia 3.358491
## 23 Guatemala 3.350000
chocolate %>%
filter(country_of_bean_origin=="Bonnat") %>%
count()
## n
## 1 0
chocolate %>%
mutate(Rating_Percantege = (100-((4-.$rating)/0.1)*5)) %>%
mutate(Class = ifelse(Rating_Percantege <25, "Low",
ifelse(Rating_Percantege>25 & Rating_Percantege<50,
"Medium", ifelse(Rating_Percantege>50 & Rating_Percantege<70,
"Tasty", "Excellent")))) %>%
head()
## ref company_manufacturer company_location review_date country_of_bean_origin
## 1 2454 5150 U.S.A. 2019 Tanzania
## 2 2458 5150 U.S.A. 2019 Dominican Republic
## 3 2454 5150 U.S.A. 2019 Madagascar
## 4 2542 5150 U.S.A. 2021 Fiji
## 5 2546 5150 U.S.A. 2021 Venezuela
## 6 2546 5150 U.S.A. 2021 Uganda
## specific_bean_origin_or_bar_name cocoa_percent ingredients
## 1 Kokoa Kamili, batch 1 76 3- B,S,C
## 2 Zorzal, batch 1 76 3- B,S,C
## 3 Bejofo Estate, batch 1 76 3- B,S,C
## 4 Matasawalevu, batch 1 68 3- B,S,C
## 5 Sur del Lago, batch 1 72 3- B,S,C
## 6 Semuliki Forest, batch 1 80 3- B,S,C
## most_memorable_characteristics rating Rating_Percantege Class
## 1 rich cocoa, fatty, bready 3.25 62.5 Tasty
## 2 cocoa, vegetal, savory 3.50 75.0 Excellent
## 3 cocoa, blackberry, full body 3.75 87.5 Excellent
## 4 chewy, off, rubbery 3.00 50.0 Excellent
## 5 fatty, earthy, moss, nutty,chalky 3.00 50.0 Excellent
## 6 mildly bitter, basic cocoa, fatty 3.25 62.5 Tasty
nmmaps <- read.csv("https://www.cedricscherer.com/data/chicago-nmmaps-custom.csv")
head(nmmaps)
## city date temp o3 dewpoint pm10 season yday month year
## 1 chic 1997-01-01 36.0 5.659256 37.50 13.052268 Winter 1 Jan 1997
## 2 chic 1997-01-02 45.0 5.525417 47.25 41.948600 Winter 2 Jan 1997
## 3 chic 1997-01-03 40.0 6.288548 38.00 27.041751 Winter 3 Jan 1997
## 4 chic 1997-01-04 51.5 7.537758 45.50 25.072573 Winter 4 Jan 1997
## 5 chic 1997-01-05 27.0 20.760798 11.25 15.343121 Winter 5 Jan 1997
## 6 chic 1997-01-06 17.0 14.940874 5.75 9.364655 Winter 6 Jan 1997
nmmaps %>%
ggplot( aes(x = date, y = temp, color = year)) +
geom_point() +
facet_wrap(~year) +
labs(title = "Relationship Between Date&Temp Based on Year") +
theme_bw()
comment: They have similar pattern. We can see that 1999 has the greatest peak among all, while 1997 has the lowest deep point.
nmmaps$season <- factor(nmmaps$season, levels=c("Autumn","Spring","Winter","Summer"))
class(nmmaps$season)
## [1] "factor"
nmmaps %>%
ggplot(aes(x=date, y=temp, color=season)) +
geom_point()+
labs(title = "Date&Temp According to Season") +
theme_minimal()
comment: It can be seen that summer has the highest temp. while winter has the lowest generally. Autumn is spread widely. Since the date is constantly changing, seasons have a wavy pattern.
nmmaps %>%
select(temp, dewpoint) %T>%
cor() %>%
plot(., main="Relation of Temp&Dewpoint", col="darkgreen", pch=5)
comment: They have a positive, strong linear relationship.
The source that has been used in the question is here.
link <- "https://scedc.caltech.edu/recent/Quakes/quakes0.html"
mask <- GET(link)
hcontent <- content(mask, "text")
html_format <- read_html(hcontent)
table <- html_format %>%
html_nodes("table") %>%
html_table()
df <- as.data.frame(table)
head(df)
## X1 X2 X3 X4 X5 X6
## 1 MAP MAG LOCAL DATETIMEy/m/d h:m:s LATdeg LONdeg DEPTHkm
## 2 map 1.1 2024/04/19 04:18:22 38.820N 122.763W 2.05
## 3 map 1.4 2024/04/19 04:07:59 38.150N 117.844W 7.1
## 4 map 1.5 2024/04/19 03:59:44 38.843N 122.817W 1.67
## 5 map 0.7 2024/04/19 03:50:02 33.203N 116.626W 17.79
## 6 map 0.7 2024/04/19 03:40:33 36.520N 115.816W 11.5
## X7
## 1 LOCATION
## 2 3 km ( 2 mi) W of Cobb, CA
## 3 54 km (34 mi) W of Tonopah, NV
## 4 8 km ( 5 mi) WNW of Cobb, CA
## 5 9 km ( 6 mi) S of Warner Springs, CA
## 6 39 km (24 mi) NNE of Pahrump, NV
Note: I took recitation6 notes as a reference in this part.
As it can be seen, the header slip to first row so it should be fixed.
header <- df[1,]
colnames(df) <- header
df <- df[-1, ]
head(df)
## MAP MAG LOCAL DATETIMEy/m/d h:m:s LATdeg LONdeg DEPTHkm
## 2 map 1.1 2024/04/19 04:18:22 38.820N 122.763W 2.05
## 3 map 1.4 2024/04/19 04:07:59 38.150N 117.844W 7.1
## 4 map 1.5 2024/04/19 03:59:44 38.843N 122.817W 1.67
## 5 map 0.7 2024/04/19 03:50:02 33.203N 116.626W 17.79
## 6 map 0.7 2024/04/19 03:40:33 36.520N 115.816W 11.5
## 7 map 1.1 2024/04/19 03:36:22 38.812N 122.829W 1.03
## LOCATION
## 2 3 km ( 2 mi) W of Cobb, CA
## 3 54 km (34 mi) W of Tonopah, NV
## 4 8 km ( 5 mi) WNW of Cobb, CA
## 5 9 km ( 6 mi) S of Warner Springs, CA
## 6 39 km (24 mi) NNE of Pahrump, NV
## 7 7 km ( 5 mi) WNW of The Geysers, CA
df %<>%
mutate(Scale= ifelse(MAG< 1.5, "Minor", ifelse(MAG<3, "Medium", "Strong")))
head(df)
## MAP MAG LOCAL DATETIMEy/m/d h:m:s LATdeg LONdeg DEPTHkm
## 2 map 1.1 2024/04/19 04:18:22 38.820N 122.763W 2.05
## 3 map 1.4 2024/04/19 04:07:59 38.150N 117.844W 7.1
## 4 map 1.5 2024/04/19 03:59:44 38.843N 122.817W 1.67
## 5 map 0.7 2024/04/19 03:50:02 33.203N 116.626W 17.79
## 6 map 0.7 2024/04/19 03:40:33 36.520N 115.816W 11.5
## 7 map 1.1 2024/04/19 03:36:22 38.812N 122.829W 1.03
## LOCATION Scale
## 2 3 km ( 2 mi) W of Cobb, CA Minor
## 3 54 km (34 mi) W of Tonopah, NV Minor
## 4 8 km ( 5 mi) WNW of Cobb, CA Medium
## 5 9 km ( 6 mi) S of Warner Springs, CA Minor
## 6 39 km (24 mi) NNE of Pahrump, NV Minor
## 7 7 km ( 5 mi) WNW of The Geysers, CA Minor
library(leaflet)
colors <- colorFactor(c("mediumpurple4", "violetred4", "darkgreen"),
domain = df$Scale)
To easier access.
colnames(df)[3] <- "Date"
The variables are all character format so first we should turn them into numeric variables.
df$LATdeg <- gsub("N", "", df$LATdeg)
df$LONdeg <- gsub("W", "", df$LON)
df$MAG <- as.numeric(df$MAG)
df$LATdeg <- as.numeric(df$LATdeg)
df$LONdeg <- as.numeric(df$LONdeg)
df$DEPTHkm <- as.numeric(df$DEPTHkm)
str(df)
## 'data.frame': 827 obs. of 8 variables:
## $ MAP : chr "map" "map" "map" "map" ...
## $ MAG : num 1.1 1.4 1.5 0.7 0.7 1.1 0.4 0.6 2.1 -0.1 ...
## $ Date : chr "2024/04/19 04:18:22" "2024/04/19 04:07:59" "2024/04/19 03:59:44" "2024/04/19 03:50:02" ...
## $ LATdeg : num 38.8 38.1 38.8 33.2 36.5 ...
## $ LONdeg : num 123 118 123 117 116 ...
## $ DEPTHkm : num 2.05 7.1 1.67 17.79 11.5 ...
## $ LOCATION: chr "3 km ( 2 mi) W of Cobb, CA" "54 km (34 mi) W of Tonopah, NV" "8 km ( 5 mi) WNW of Cobb, CA" "9 km ( 6 mi) S of Warner Springs, CA" ...
## $ Scale : chr "Minor" "Minor" "Medium" "Minor" ...
Now we can use it to visualization.
df %>%
leaflet() %>%
addTiles() %>%
addCircles(~LONdeg, ~LATdeg, radius = df$DEPTHkm,
popup = paste0("<b>Date: </b>", df$Date,"<br>", "<b>Location: </b>", df$LOCATION, "<br>",
"<b>Magnitude: </b>",df$MAG,
"<b>Depth: </b>",df$DEPTHkm ),
label=~LOCATION,color=~colors(Scale)) %>%
setView(lng = mean(df$LONdeg),lat = mean(df$LATdeg),zoom = 6 )