Skip to content

Commit

Permalink
shiny article, pokemon data fix,
Browse files Browse the repository at this point in the history
  • Loading branch information
jbkunst committed May 31, 2021
1 parent a503537 commit 2d01d1a
Show file tree
Hide file tree
Showing 236 changed files with 11,339 additions and 3,880 deletions.
2 changes: 1 addition & 1 deletion R/proxy.R
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ hcpxy_update <- function(proxy, ...) {
#' @param proxy A `higchartProxy` object.
#' @param id A character vector indicating the `id` (or `id`s) of the series to update.
#' @param ... Arguments defined in \url{https://api.highcharts.com/highcharts/plotOptions.series}.
#' The argumnes will be the same for each series. So if you want update data it
#' The arguments will be the same for each series. So if you want update data it
#' is used this function sequentially for each series.
#'
#' @export
Expand Down
74 changes: 20 additions & 54 deletions data-raw/pokemon.R
Original file line number Diff line number Diff line change
@@ -1,30 +1,7 @@
library("dplyr")
library("readr")
library("rvest")
library("purrr")
library("stringr")
library("tidyr")
library("highcharter")
library("tsne")
library("ggplot2")
library("htmltools")

#'
#' Time ago, when I was a younger man I know pokemon, the 150 pokemon. Then, after
#' 10 year there are over 700 with new types new, new regions, etc. So
#' to know the status of all these monsters I download the data and make some
#' chart and see te actual status.
#'
#' ![I have no idea](/images/pokemon-visualize-em-all/ihavenoidea.gif)
#'
#' ## Data
#'
#' There is a pokemon api http://pokeapi.co/. But we want all the pokemon data once so
#' we can go to the repository and found the raw data https://github.com/phalt/pokeapi/tree/master/data/v2/csv .
#' We'll need other type of data like type's colors, icon images. This data we founded here
#' http://bulbapedia.bulbagarden.net/wiki/List_of_Pok%C3%A9mon_by_base_stats_(Generation_VI-present) and
#' http://pokemon-uranium.wikia.com/wiki/Template:fire_color.
#'
library(tidyverse)
library(rvest)



path <- function(x) paste0("https://raw.githubusercontent.com/phalt/pokeapi/master/data/v2/csv/", x)

Expand Down Expand Up @@ -61,17 +38,17 @@ dfegg <- read_csv(path("egg_groups.csv")) %>%
select(species_id, ranking, identifier) %>%
spread(ranking, identifier)

dfimg <- "https://github.com/phalt/pokeapi/tree/master/data/Pokemon_XY_Sprites" %>%
read_html() %>%
html_nodes("tr.js-navigation-item > .content > .css-truncate a") %>%
map_df(function(x) {
url <- x %>% html_attr("href")
data_frame(
id = str_extract(basename(url), "\\d+"),
url_image = basename(url)
)
}) %>%
mutate(id = as.numeric(id))
# dfimg <- "https://github.com/phalt/pokeapi/tree/master/data/Pokemon_XY_Sprites" %>%
# read_html() %>%
# html_nodes("tr.js-navigation-item > .content > .css-truncate a") %>%
# map_df(function(x) {
# url <- x %>% html_attr("href")
# data_frame(
# id = str_extract(basename(url), "\\d+"),
# url_image = basename(url)
# )
# }) %>%
# mutate(id = as.numeric(id))

url_bulbapedia_list <- "http://bulbapedia.bulbagarden.net/wiki/List_of_Pok%C3%A9mon_by_base_stats_(Generation_VI-present)"

Expand Down Expand Up @@ -101,7 +78,7 @@ dfcolor <- map_df(na.omit(unique(c(dftype$type_1, dftype$type_2))), function(t)
data_frame(type = t, color = paste0("#", col))
})

dfcolorf <- expand.grid(
dfcolorf <- crossing(
color_1 = dfcolor$color, color_2 = dfcolor$color,
stringsAsFactors = FALSE
) %>%
Expand All @@ -110,7 +87,7 @@ dfcolorf <- expand.grid(
do({
n <- 100
p <- 0.25
data_frame(color_f = colorRampPalette(c(.$color_1, .$color_2))(n)[round(n * p)])
tibble(color_f = colorRampPalette(c(.$color_1, .$color_2))(n)[round(n * p)])
})

# THE join
Expand All @@ -121,21 +98,10 @@ pokemon <- dfpkmn %>%
left_join(dfcolor %>% rename(type_2 = type, color_2 = color), by = "type_2") %>%
left_join(dfcolorf, by = c("color_1", "color_2")) %>%
left_join(dfegg, by = "species_id") %>%
left_join(dfimg, by = "id") %>%
# left_join(dfimg, by = "id") %>%
left_join(dficon, by = "id")

pokemon <- pokemon %>%
mutate(color_f = ifelse(is.na(color_f), color_1, color_f)) %>%
filter(!is.na(url_image))

devtools::use_data(pokemon, overwrite = TRUE)

rm(list = setdiff(ls(), "pokemon"))

names(pokemon) %>%
sprintf("#' \\item \\code{%s}:\n", .) %>%
cat()

str(pokemon)
mutate(color_f = ifelse(is.na(color_f), color_1, color_f))

# EXAMPLE -----------------------------------------------------------------
usethis::use_data(pokemon, overwrite = TRUE)
Binary file modified data/pokemon.rda
Binary file not shown.
11 changes: 8 additions & 3 deletions docs/CODE_OF_CONDUCT.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions docs/CONTRIBUTING.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions docs/LICENSE-text.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions docs/PULL_REQUEST_TEMPLATE.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 21 additions & 16 deletions docs/articles/howtos.html

Large diffs are not rendered by default.

Loading

0 comments on commit 2d01d1a

Please sign in to comment.