-
Notifications
You must be signed in to change notification settings - Fork 36
/
meteorites.Rmd
92 lines (75 loc) · 2.5 KB
/
meteorites.Rmd
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
---
title: "meteorites"
output: html_document
---
```{r setup, include=FALSE, echo=FALSE, message=FALSE}
library(formattable)
library(gridExtra)
library(dplyr)
library(tidyr)
library(reshape2)
library(ggplot2)
library(ggraph)
library(plotly)
library(readr)
```
```{r read}
df <- read_csv("meteorites.csv")
```
```{r cleaning}
df <- df %>%
filter(year>=860 & year<=2016) %>% # filter out weird years
filter(reclong<=180 & reclong>=-180 & (reclat!=0 | reclong!=0)) # filter out weird locations
```
```{r}
summary(df$mass)
```
```{r bigmass}
#convert coord to countries
library(rworldmap)
points=df %>%
filter(mass > 18540) %>%
select(reclat, reclong)
coords2country = function(points)
{
countriesSP <- getMap(resolution='low')
#countriesSP <- getMap(resolution='high') #you could use high res map from rworldxtra if you were concerned about detail
# convert our list of points to a SpatialPoints object
# pointsSP = SpatialPoints(points, proj4string=CRS(" +proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs +towgs84=0,0,0"))
#setting CRS directly to that from rworldmap
pointsSP = SpatialPoints(points, proj4string=CRS(proj4string(countriesSP)))
# use 'over' to get indices of the Polygons object containing each point
indices = over(pointsSP, countriesSP)
# return the ADMIN names of each country
indices$ADMIN
#indices$ISO3 # returns the ISO3 code
#indices$continent # returns the continent (6 continent model)
#indices$REGION # returns the continent (7 continent model)
}
points$country=coords2country(points)
```
```{r classification}
df10 <- df %>% left_join(points, by = c("reclat", "reclong")) %>%
arrange(desc(mass)) %>%
select(-c(id, GeoLocation)) %>%
#mutate(class=ifelse(grepl("L/LL",recclass),"L/LL",recclass)) %>%
mutate(class=sapply(strsplit(recclass, ","), "[", 1))%>%
mutate(class = sub("[^[:alpha:]]+", "", class)) %>%
mutate(class = ifelse(grepl("LLL",class),"L/LL",class)) %>%
mutate(group = ifelse(grepl("Mesosiderite",class)|grepl("Pallasite",class),"Mixture",
ifelse(grepl("Iron",class), "Iron","Stony")))
write.csv(df10, 'df10.csv')
```
```{r}
df10 %>%
filter(year>=1760, country%in%c('Antarctica')) %>%
ggplot(aes(year, mass, fill=country)) +
geom_dotplot(binaxis = "x", dotsize=0.3) +
theme_void() +
theme(legend.position = 'None') +facet_wrap(~country)
```
```{r timeline}
timeline <- df10 %>%
select(start_date=year, category=country, facet=country, content_text= mass)
write.csv(timeline, 'timeline.csv')
```