-
Notifications
You must be signed in to change notification settings - Fork 7
Room 1 - volcano script added #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
library(tidyverse) | ||
library(lubridate) | ||
library(ggplot2) | ||
library(maps) | ||
library(patchwork) | ||
|
||
#' This is script with analysis of volcanos for my | ||
#' geological article. | ||
|
||
volcano <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-05-12/volcano.csv') | ||
|
||
processed_volcano <- volcano %>% | ||
mutate(logpop10 = log10(population_within_10_km+0.1)) %>% | ||
select(primary_volcano_type, pop=logpop10, longitude, latitude) | ||
|
||
# cleaning data a bit as there are some plural versions of volcano names | ||
# that mean essentially the same | ||
processed_volcano$primary_volcano_type <- | ||
recode(processed_volcano$primary_volcano_type, Stratovolcano="Stratovolcano(es)") | ||
|
||
processed_volcano$primary_volcano_type <- | ||
recode(processed_volcano$primary_volcano_type, `Shield(s)`="Shield") | ||
|
||
volcano_types <- processed_volcano %>% group_by(primary_volcano_type) %>% | ||
summarise(count = n()) %>% | ||
arrange(desc(count)) %>% head(8) | ||
|
||
# NA types become Other as we want to include them in the analysis | ||
processed_volcano$primary_volcano_type <- processed_volcano$primary_volcano_type %>% | ||
replace_na("Other") | ||
|
||
sc_max <- max(processed_volcano$pop) | ||
sc_min <- min(processed_volcano$pop) | ||
|
||
col_palette = c("#d11141", "#00b159", "#00aedb", "#f37735", "#ffc425", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps better to use an existing colour palette. Indexing col_palette in this case doesn't work if colid > 15. |
||
"#3aefaf", "#0b57dd", "#f666b7", "#cf1833", "#a35c0a", | ||
"#bc0bfe", "#61ff41", "#eabf72", "#09dbc3", "#ffffff") | ||
|
||
do_map = function(vulc_type, colid = NULL) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be defined before this script, not in the middle of it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be good to have a brief comment explaining what this function does |
||
dotcol <- ifelse(is.null(colid), "#fdff00", col_palette[colid]) | ||
processed_volcano %>% | ||
filter(primary_volcano_type == vulc_type) %>% | ||
ggplot(aes(longitude, latitude, size = pop)) + | ||
borders(colour = "#396067", fill = "#383949") + | ||
geom_point(shape = 16, colour = dotcol, fill = "#ff5800", alpha = 0.6) + | ||
scale_radius(range = c(1, 8), limits = c(sc_min, sc_max)) + | ||
theme(legend.position = "none", | ||
plot.background = element_rect(fill = "#2b272e"), | ||
plot.title = element_text(color = "white", size = 12, face = "bold")) + | ||
ggtitle(paste("Volcano type: ", vulc_type)) | ||
} | ||
|
||
|
||
plot.list <- lapply(seq(1, length(volcano_types$primary_volcano_type)), | ||
function(i) do_map(volcano_types$primary_volcano_type[i], i)) | ||
|
||
plt <- wrap_plots(plot.list, nrow = 2) | ||
ggsave("plot.pdf", plot = plt) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would put this in a seperate function