-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmeteorite-impacts.Rmd
95 lines (73 loc) · 2.93 KB
/
meteorite-impacts.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
92
93
94
---
title: "Meteorite Impacts"
author: "Dean Marchiori"
date: "6/18/2019"
output: html_document
editor_options:
chunk_output_type: console
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Intro
This week's dataset is a dataset all about meteorites, where they fell and when they fell! Data comes from the Meteoritical Society by way of NASA.
https://github.com/rfordatascience/tidytuesday/tree/master/data/2019/2019-06-11
## Loading packages and reading in data
```{r message=FALSE, warning=FALSE}
library(tidyverse)
library(maps)
library(cowplot)
library(ggrepel)
meteorites <- readr::read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2019/2019-06-11/meteorites.csv")
```
# Preprocessing
Here I limit the dataset to those records that fall within the bounding box of
Australia.
To enable selective labelling I make use of `ifelse` to create a new column with
mostly `NA` values except the records I want to print as labels.
```{r}
# Aus. Bounding Box
bbox <- c(113.338953078, -45.6345972634, 153.569469029, -10.6681857235)
meteorites_processed <- meteorites %>%
mutate(class = fct_lump(class, 5)) %>%
filter(long > bbox[1], long < bbox[3],
lat > bbox[2], lat < bbox[4],
name_type != "Relict") %>%
mutate(met_name = ifelse(mass >= 2000000, name, NA))
```
## Making Plots
The idea here is to creatre two plots and use the `cowplot` package to
draw one as an inset.
```{r}
map <- borders(database = "world",
regions = c("Australia"),
colour="gray50",
fill="gray50",
ylim = c(bbox[2], bbox[4]),
xlim = c(bbox[1], bbox[3]))
size_guide <- meteorites_processed %>%
top_n(5, mass) %>%
mutate(name = fct_reorder(name, mass)) %>%
ggplot(aes(name, 1, size = mass)) +
geom_point(show.legend = F, alpha = 0.6, colour = "red") +
scale_size(range = c(1, 20)) +
geom_text(aes(name, 1, label = name), nudge_y = -0.15, size = 2.5) +
geom_text(aes(name, 1, label = year), nudge_y = -0.2, size = 2.5) +
geom_text(aes(name, 1, label = paste(mass/1000, "kg")), size = 2.5, nudge_y = -0.25) +
scale_y_continuous(limits = c(0, 1.5)) +
theme_void()
ozmap <- ggplot() +
map +
theme_void() +
geom_point(data = meteorites_processed, aes(long, lat, size = sqrt(mass), colour = class), alpha = 0.3, show.legend = T) +
scale_size(range = c(0.1, 20), guide = FALSE) +
scale_color_viridis_d(direction = -1) +
geom_label_repel(data = meteorites_processed, aes(long, lat, label = met_name), size = 3, nudge_y = -3, nudge_x = 3) +
labs(title = "Australian Meteorite Landings",
subtitle = "All recorded meteorite landings by NASA",
caption = "source: https://data.nasa.gov/Space-Science/Meteorite-Landings/gh4g-9sfh/data",
colour = "Meteor \n Class")
ggdraw() +
draw_plot(ozmap) +
draw_plot(size_guide, x = 0.0, y = -0.3, width = 0.55, height = .75)
```