mirror of
https://github.com/msberends/AMR.git
synced 2025-07-08 11:11:54 +02:00
(v0.9.0.9008) Happy new year! Add lifecycles
This commit is contained in:
@ -1,8 +1,39 @@
|
||||
# ==================================================================== #
|
||||
# TITLE #
|
||||
# Antimicrobial Resistance (AMR) Analysis #
|
||||
# #
|
||||
# SOURCE #
|
||||
# https://gitlab.com/msberends/AMR #
|
||||
# #
|
||||
# LICENCE #
|
||||
# (c) 2018-2020 Berends MS, Luz CF et al. #
|
||||
# #
|
||||
# This R package is free software; you can freely use and distribute #
|
||||
# it for both personal and commercial purposes under the terms of the #
|
||||
# GNU General Public License version 2.0 (GNU GPL-2), as published by #
|
||||
# the Free Software Foundation. #
|
||||
# #
|
||||
# We created this package for both routine data analysis and academic #
|
||||
# research and it was publicly released in the hope that it will be #
|
||||
# useful, but it comes WITHOUT ANY WARRANTY OR LIABILITY. #
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
# Read and format data ----------------------------------------------------
|
||||
|
||||
library(tidyverse)
|
||||
library(maps)
|
||||
library(httr)
|
||||
|
||||
GET_df <- function(ip) {
|
||||
ip <- paste0("https://ipinfo.io/", ip, "?token=089aa7765ee912")
|
||||
result <- ip %>% GET()
|
||||
stop_for_status(result)
|
||||
result %>%
|
||||
content(type = "text", encoding = "UTF-8") %>%
|
||||
jsonlite::fromJSON(flatten = TRUE) %>%
|
||||
as_tibble()
|
||||
}
|
||||
|
||||
# get website analytics
|
||||
source("data-raw/country_analysis_url_token.R")
|
||||
@ -10,37 +41,64 @@ url_json <- paste0(country_analysis_url,
|
||||
"/index.php?&module=API&token_auth=",
|
||||
country_analysis_token,
|
||||
"&method=Live.getLastVisitsDetails&idSite=3&language=en&expanded=1&date=2018-01-01,2028-01-01&period=range&filter_limit=-1&format=JSON&segment=&translateColumnNames=1")
|
||||
|
||||
data_json <- jsonlite::read_json(url_json)
|
||||
data <- tibble(
|
||||
timestamp_server = as.POSIXct(sapply(data_json, function(x) x$serverTimestamp), origin = "1970-01-01"),
|
||||
country = sapply(data_json, function(x) x$country))
|
||||
ipaddress = sapply(data_json, function(x) x$visitIp))
|
||||
rm(data_json)
|
||||
|
||||
# add country data based on IP address and ipinfo.io API
|
||||
unique_ip <- unique(data$ipaddress)
|
||||
ip_tbl <- GET_df(unique_ip[1])
|
||||
p <- progress_estimated(n = length(unique_ip) - 1, min_time = 0)
|
||||
for (i in 2:length(unique_ip)) {
|
||||
p$tick()$print()
|
||||
ip_tbl <- ip_tbl %>%
|
||||
bind_rows(GET_df(unique_ip[i]))
|
||||
}
|
||||
|
||||
# how many?
|
||||
n_distinct(data$country[data$country != "Unknown"])
|
||||
|
||||
n_distinct(ip_tbl$country)
|
||||
|
||||
# add long and lat
|
||||
ip_tbl <- ip_tbl %>%
|
||||
separate(loc, into = c("y", "x"), sep = ",", remove = FALSE, convert = TRUE)
|
||||
|
||||
# Plot world map ----------------------------------------------------------
|
||||
|
||||
countries_name <- sort(unique(data$country))
|
||||
countries_name <- countries_name[countries_name != "Unknown"]
|
||||
countries_iso <- countrycode::countrycode(countries_name, 'country.name', 'iso3c')
|
||||
countries_geometry <- sf::st_as_sf(map('world', plot = FALSE, fill = TRUE)) %>%
|
||||
mutate(countries_code = countrycode::countrycode(ID,
|
||||
origin = 'country.name',
|
||||
destination = 'iso2c',
|
||||
custom_match = c("Ascension Island" = "GB", # Great Britain
|
||||
"Azores" = "PT", # Portugal
|
||||
"Barbuda" = "GB", # Great Britain
|
||||
"Bonaire" = "BQ", # Bonaire, Saint Eustatius and Saba
|
||||
"Canary Islands" = "ES", # Spain
|
||||
"Chagos Archipelago" = "MU", # Mauritius
|
||||
"Grenadines" = "VC", # Saint Vincent and the Grenadines
|
||||
"Heard Island" = "AU", # Australia
|
||||
"Kosovo" = "XK",
|
||||
"Madeira Islands" = "PT", # Portugal
|
||||
"Micronesia" = "FM",
|
||||
"Saba" = "BQ", # Bonaire, Saint Eustatius and Saba
|
||||
"Saint Martin" = "MF",
|
||||
"Siachen Glacier" = "IN", # India
|
||||
"Sint Eustatius" = "BQ" # Bonaire, Saint Eustatius and Saba
|
||||
)),
|
||||
included = as.integer(countries_code %in% ip_tbl$country),
|
||||
not_antarctica = as.integer(ID != "Antarctica"),
|
||||
countries_name = ifelse(included == 1, ID, NA))
|
||||
|
||||
world1 <- sf::st_as_sf(map('world', plot = FALSE, fill = TRUE)) %>%
|
||||
mutate(countries_code = countrycode::countrycode(ID, 'country.name', 'iso3c'),
|
||||
included = as.integer(countries_code %in% countries_iso)) %>%
|
||||
mutate(not_antarctica = as.integer(ID != "Antarctica"))
|
||||
|
||||
countries_plot <- ggplot(world1) +
|
||||
geom_sf(aes(fill = included, colour = not_antarctica), size = 0.25) +
|
||||
countries_plot <- ggplot(countries_geometry) +
|
||||
geom_sf(aes(fill = included, colour = not_antarctica),
|
||||
size = 0.25,
|
||||
show.legend = FALSE) +
|
||||
theme_minimal() +
|
||||
theme(legend.position = "none",
|
||||
panel.grid = element_blank(),
|
||||
theme(panel.grid = element_blank(),
|
||||
axis.title = element_blank(),
|
||||
axis.text = element_blank()) +
|
||||
scale_fill_gradient(low = "white", high = "#CAD6EA") +
|
||||
scale_fill_gradient(low = "white", high = "#CAD6EA", ) +
|
||||
# this makes the border Antarctica turn white (invisible):
|
||||
scale_colour_gradient(low = "white", high = "#81899B")
|
||||
|
||||
@ -49,17 +107,23 @@ countries_plot_mini$data <- countries_plot_mini$data %>% filter(ID != "Antarctic
|
||||
countries_plot_mini <- countries_plot_mini + scale_colour_gradient(low = "#81899B", high = "#81899B")
|
||||
countries_plot_big <- countries_plot +
|
||||
labs(title = tools::toTitleCase("Countries where the AMR package for R was downloaded from"),
|
||||
subtitle = paste0("Between March 2018 - ", format(Sys.Date(), "%B %Y"))) +
|
||||
subtitle = paste0("Between March 2018 (first release) and ", format(Sys.Date(), "%B %Y"), ". The dots denote visitors on our website https://gitlab.io/msberends/AMR.")) +
|
||||
theme(plot.title = element_text(size = 16, hjust = 0.5),
|
||||
plot.subtitle = element_text(size = 12, hjust = 0.5)) +
|
||||
geom_text(aes(x = -170,
|
||||
y = -70,
|
||||
label = stringr::str_wrap(paste0("Countries (n = ",
|
||||
length(countries_name), "): ",
|
||||
paste(countries_name, collapse = ", ")),
|
||||
length(countries_name[!is.na(countries_name)]), "): ",
|
||||
paste(countries_name[!is.na(countries_name)], collapse = ", ")),
|
||||
200)),
|
||||
hjust = 0,
|
||||
size = 4)
|
||||
size = 4) +
|
||||
# points of visitors
|
||||
geom_point(data = ip_tbl,
|
||||
aes(x = x, y = y),
|
||||
size = 1,
|
||||
colour = "#81899B")
|
||||
|
||||
# main website page
|
||||
ggsave("pkgdown/logos/countries.png",
|
||||
width = 6,
|
||||
@ -79,31 +143,31 @@ ggsave("pkgdown/logos/countries_large.png",
|
||||
|
||||
|
||||
# Gibberish ---------------------------------------------------------------
|
||||
|
||||
p1 <- data %>%
|
||||
group_by(country) %>%
|
||||
summarise(first = min(timestamp_server)) %>%
|
||||
arrange(first) %>%
|
||||
mutate(n = row_number()) %>%
|
||||
ggplot(aes(x = first, y = n)) +
|
||||
geom_line() +
|
||||
geom_point(aes(x = max(first), y = max(n)), size = 3) +
|
||||
scale_x_datetime(date_breaks = "2 months", date_labels = "%B %Y") +
|
||||
labs(x = NULL, y = "Number of countries")
|
||||
|
||||
package_releases <- read_html("https://cran.r-project.org/src/contrib/Archive/AMR/") %>%
|
||||
rvest::html_table() %>%
|
||||
.[[1]] %>%
|
||||
as_tibble(.name_repair = "unique") %>%
|
||||
filter(`Last modified` != "") %>%
|
||||
transmute(version = gsub("[^0-9.]", "",
|
||||
gsub(".tar.gz", "", Name)),
|
||||
datetime = as.POSIXct(`Last modified`)) %>%
|
||||
# add current
|
||||
bind_rows(tibble(version = as.character(packageVersion("AMR")),
|
||||
datetime = as.POSIXct(packageDate("AMR")))) %>%
|
||||
# remove the ones not plottable
|
||||
filter(datetime > min(p1$data$first))
|
||||
|
||||
p1 + geom_linerange(data = package_releases, aes(x = datetime, ymin = 0, ymax = 80), colour = "red", inherit.aes = FALSE)
|
||||
|
||||
#
|
||||
# p1 <- data %>%
|
||||
# group_by(country) %>%
|
||||
# summarise(first = min(timestamp_server)) %>%
|
||||
# arrange(first) %>%
|
||||
# mutate(n = row_number()) %>%
|
||||
# ggplot(aes(x = first, y = n)) +
|
||||
# geom_line() +
|
||||
# geom_point(aes(x = max(first), y = max(n)), size = 3) +
|
||||
# scale_x_datetime(date_breaks = "2 months", date_labels = "%B %Y") +
|
||||
# labs(x = NULL, y = "Number of countries")
|
||||
#
|
||||
# package_releases <- read_html("https://cran.r-project.org/src/contrib/Archive/AMR/") %>%
|
||||
# rvest::html_table() %>%
|
||||
# .[[1]] %>%
|
||||
# as_tibble(.name_repair = "unique") %>%
|
||||
# filter(`Last modified` != "") %>%
|
||||
# transmute(version = gsub("[^0-9.]", "",
|
||||
# gsub(".tar.gz", "", Name)),
|
||||
# datetime = as.POSIXct(`Last modified`)) %>%
|
||||
# # add current
|
||||
# bind_rows(tibble(version = as.character(packageVersion("AMR")),
|
||||
# datetime = as.POSIXct(packageDate("AMR")))) %>%
|
||||
# # remove the ones not plottable
|
||||
# filter(datetime > min(p1$data$first))
|
||||
#
|
||||
# p1 + geom_linerange(data = package_releases, aes(x = datetime, ymin = 0, ymax = 80), colour = "red", inherit.aes = FALSE)
|
||||
#
|
||||
|
@ -1,5 +1,27 @@
|
||||
# Run this file to update the package -------------------------------------
|
||||
# ==================================================================== #
|
||||
# TITLE #
|
||||
# Antimicrobial Resistance (AMR) Analysis #
|
||||
# #
|
||||
# SOURCE #
|
||||
# https://gitlab.com/msberends/AMR #
|
||||
# #
|
||||
# LICENCE #
|
||||
# (c) 2018-2020 Berends MS, Luz CF et al. #
|
||||
# #
|
||||
# This R package is free software; you can freely use and distribute #
|
||||
# it for both personal and commercial purposes under the terms of the #
|
||||
# GNU General Public License version 2.0 (GNU GPL-2), as published by #
|
||||
# the Free Software Foundation. #
|
||||
# #
|
||||
# We created this package for both routine data analysis and academic #
|
||||
# research and it was publicly released in the hope that it will be #
|
||||
# useful, but it comes WITHOUT ANY WARRANTY OR LIABILITY. #
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
# Run this file to update the package using: -------------------------------
|
||||
# source("data-raw/internals.R")
|
||||
# --------------------------------------------------------------------------
|
||||
|
||||
# See 'data-raw/eucast_rules.tsv' for the EUCAST reference file
|
||||
eucast_rules_file <- utils::read.delim(file = "data-raw/eucast_rules.tsv",
|
||||
|
@ -6,16 +6,16 @@
|
||||
# https://gitlab.com/msberends/AMR #
|
||||
# #
|
||||
# LICENCE #
|
||||
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
|
||||
# (c) 2018-2020 Berends MS, Luz CF et al. #
|
||||
# #
|
||||
# This R package is free software; you can freely use and distribute #
|
||||
# it for both personal and commercial purposes under the terms of the #
|
||||
# GNU General Public License version 2.0 (GNU GPL-2), as published by #
|
||||
# the Free Software Foundation. #
|
||||
# #
|
||||
# This R package was created for academic research and was publicly #
|
||||
# released in the hope that it will be useful, but it comes WITHOUT #
|
||||
# ANY WARRANTY OR LIABILITY. #
|
||||
# We created this package for both routine data analysis and academic #
|
||||
# research and it was publicly released in the hope that it will be #
|
||||
# useful, but it comes WITHOUT ANY WARRANTY OR LIABILITY. #
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
|
@ -6,16 +6,16 @@
|
||||
# https://gitlab.com/msberends/AMR #
|
||||
# #
|
||||
# LICENCE #
|
||||
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
|
||||
# (c) 2018-2020 Berends MS, Luz CF et al. #
|
||||
# #
|
||||
# This R package is free software; you can freely use and distribute #
|
||||
# it for both personal and commercial purposes under the terms of the #
|
||||
# GNU General Public License version 2.0 (GNU GPL-2), as published by #
|
||||
# the Free Software Foundation. #
|
||||
# #
|
||||
# This R package was created for academic research and was publicly #
|
||||
# released in the hope that it will be useful, but it comes WITHOUT #
|
||||
# ANY WARRANTY OR LIABILITY. #
|
||||
# We created this package for both routine data analysis and academic #
|
||||
# research and it was publicly released in the hope that it will be #
|
||||
# useful, but it comes WITHOUT ANY WARRANTY OR LIABILITY. #
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
|
@ -1,3 +1,24 @@
|
||||
# ==================================================================== #
|
||||
# TITLE #
|
||||
# Antimicrobial Resistance (AMR) Analysis #
|
||||
# #
|
||||
# SOURCE #
|
||||
# https://gitlab.com/msberends/AMR #
|
||||
# #
|
||||
# LICENCE #
|
||||
# (c) 2018-2020 Berends MS, Luz CF et al. #
|
||||
# #
|
||||
# This R package is free software; you can freely use and distribute #
|
||||
# it for both personal and commercial purposes under the terms of the #
|
||||
# GNU General Public License version 2.0 (GNU GPL-2), as published by #
|
||||
# the Free Software Foundation. #
|
||||
# #
|
||||
# We created this package for both routine data analysis and academic #
|
||||
# research and it was publicly released in the hope that it will be #
|
||||
# useful, but it comes WITHOUT ANY WARRANTY OR LIABILITY. #
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
# Reproduction of the `microorganisms` data set
|
||||
|
||||
# Data retrieved from the Catalogue of Life (CoL) through the Encyclopaedia of Life:
|
||||
|
@ -1,3 +1,24 @@
|
||||
# ==================================================================== #
|
||||
# TITLE #
|
||||
# Antimicrobial Resistance (AMR) Analysis #
|
||||
# #
|
||||
# SOURCE #
|
||||
# https://gitlab.com/msberends/AMR #
|
||||
# #
|
||||
# LICENCE #
|
||||
# (c) 2018-2020 Berends MS, Luz CF et al. #
|
||||
# #
|
||||
# This R package is free software; you can freely use and distribute #
|
||||
# it for both personal and commercial purposes under the terms of the #
|
||||
# GNU General Public License version 2.0 (GNU GPL-2), as published by #
|
||||
# the Free Software Foundation. #
|
||||
# #
|
||||
# We created this package for both routine data analysis and academic #
|
||||
# research and it was publicly released in the hope that it will be #
|
||||
# useful, but it comes WITHOUT ANY WARRANTY OR LIABILITY. #
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
# ---------------------------------------------------------------------------------
|
||||
# Reproduction of the `microorganisms` data set
|
||||
# ---------------------------------------------------------------------------------
|
||||
|
Reference in New Issue
Block a user