Animal Crossing

Looking at the unique animal personalities in Animal Crossing.
tidytuesday
Author

Ted Laderas

Published

May 5, 2020

What was your dataset?

Load your dataset in with the function below. The input is the date the dataset was issued. You should be able to get this from the tt_available() function.

critic <- readr::read_tsv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-05-05/critic.tsv')
Rows: 107 Columns: 4
── Column specification ────────────────────────────────────────────────────────
Delimiter: "\t"
chr  (2): publication, text
dbl  (1): grade
date (1): date

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
user_reviews <- readr::read_tsv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-05-05/user_reviews.tsv')
Rows: 2999 Columns: 4
── Column specification ────────────────────────────────────────────────────────
Delimiter: "\t"
chr  (2): user_name, text
dbl  (1): grade
date (1): date

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
items <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-05-05/items.csv')
Warning: One or more parsing issues, call `problems()` on your data frame for details,
e.g.:
  dat <- vroom(...)
  problems(dat)
Rows: 4565 Columns: 16
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (10): id, name, category, sell_currency, buy_currency, sources, recipe_i...
dbl  (4): num_id, sell_value, buy_value, recipe
lgl  (2): orderable, customizable

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
villagers <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-05-05/villagers.csv')
Rows: 391 Columns: 11
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (10): id, name, gender, species, birthday, personality, song, phrase, fu...
dbl  (1): row_n

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

Villagers

skimr::skim(villagers)
Data summary
Name villagers
Number of rows 391
Number of columns 11
_______________________
Column type frequency:
character 10
numeric 1
________________________
Group variables None

Variable type: character

skim_variable n_missing complete_rate min max empty n_unique whitespace
id 0 1.00 2 8 0 391 0
name 0 1.00 2 8 0 391 0
gender 0 1.00 4 6 0 2 0
species 0 1.00 3 9 0 35 0
birthday 0 1.00 3 5 0 361 0
personality 0 1.00 4 6 0 8 0
song 11 0.97 7 16 0 92 0
phrase 0 1.00 2 10 0 388 0
full_id 0 1.00 11 17 0 391 0
url 0 1.00 60 66 0 391 0

Variable type: numeric

skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist
row_n 0 1 239.9 140.7 2 117.5 240 363.5 483 ▇▇▇▇▇

Personalities by Species

species_count <- villagers %>%
  group_by(species)  %>%
  summarize(species_count = n()) %>%
  arrange(species_count)

datatable(species_count)
level_order <- villagers %>%
  group_by(species) %>% count() %>%
  arrange(desc(n)) %>%
  pull(species)

villagers %>%
  mutate(species=factor(species, levels=level_order)) %>%
  ggplot() + aes(x=species, y=personality, color=personality) %>%
  geom_count() + 
   theme_light() + theme(legend.position = "none") +
  theme(axis.text.x = element_text(angle = 90)) 

villagers %>% select(name, species, personality, url) %>%
  mutate(combo = paste(species, personality)) %>% select(name, combo, url) -> villager_index

unique_combos <- villagers %>%
  group_by(species, personality) %>% summarize(n=n()) %>%
  filter(n == 1) %>% mutate(combo=paste(species, personality)) %>%
  inner_join(y=villager_index, by=c("combo")) %>% ungroup()
`summarise()` has grouped output by 'species'. You can override using the
`.groups` argument.
out_image <- unique_combos %>%
  ggplot() + aes(x=species, y=personality, image=url, name=name) +
  geom_count() +
  geom_raster(fill="white", color="black") +
  geom_image(asp=1.2, size=0.03) + 
   theme_minimal() + theme(legend.position = "none") +
  theme(axis.text.x = element_text(angle = 90)) + labs(title="There can be only one", subtitle = "Unique Personality/Species combos in Animal Crossing")
Warning in geom_raster(fill = "white", color = "black"): Ignoring unknown
parameters: `colour`
out_image

ggsave(plot=out_image, filename = "unique_animal_personalities.pdf", width=10, height = 5)
pers_vil <- villagers %>% 
  group_by(personality, species) %>%
  summarize(count=n()) %>%
  #filter(count==1) %>%
  arrange(species) 
`summarise()` has grouped output by 'personality'. You can override using the
`.groups` argument.
pers_vil %>%
  arrange(desc(count)) %>%
  datatable()

Items

skimr::skim(items)
Data summary
Name items
Number of rows 4565
Number of columns 16
_______________________
Column type frequency:
character 10
logical 2
numeric 4
________________________
Group variables None

Variable type: character

skim_variable n_missing complete_rate min max empty n_unique whitespace
id 0 1.00 3 29 0 4200 0
name 0 1.00 3 29 0 4200 0
category 0 1.00 4 11 0 21 0
sell_currency 36 0.99 5 5 0 1 0
buy_currency 1014 0.78 5 5 0 2 0
sources 3663 0.20 3 71 0 125 0
recipe_id 3977 0.13 4 20 0 102 0
games_id 0 1.00 2 2 0 1 0
id_full 1528 0.67 8 34 0 2704 0
image_url 1528 0.67 56 82 0 2672 0

Variable type: logical

skim_variable n_missing complete_rate mean count
orderable 2775 0.39 0.45 FAL: 976, TRU: 814
customizable 3992 0.13 0.45 FAL: 316, TRU: 257

Variable type: numeric

skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist
num_id 0 1.00 3661.62 2187.95 12 1722 3569 5607 7443 ▇▇▇▇▇
sell_value 36 0.99 2261.38 11313.23 5 240 390 1000 300000 ▇▁▁▁▁
buy_value 1014 0.78 6959.65 34326.09 40 870 1300 2700 1200000 ▇▁▁▁▁
recipe 3977 0.13 4.71 6.49 1 2 3 6 90 ▇▁▁▁▁
library(tidyverse)
items %>% ggplot() +
  aes(x=category, y=buy_value) +
  geom_boxplot() +
  ylim(c(0,75000)) +
  theme(axis.text.x  = element_text(angle = 90))
Warning: Removed 1094 rows containing non-finite values (`stat_boxplot()`).

Most Expensive Items

This was the original code in my tweet:

library(gt)

 items %>% 
  top_n(10, buy_value) %>%
  arrange(desc(buy_value)) %>%
  select(name, sell_value, buy_value, category, image=image_url) %>%
  gt() %>%
   text_transform(
    locations = cells_body(vars(image)),
    fn = function(x) {
      web_image(
        url = x,
        height = 50
      )
    }
  )
Warning: Since gt v0.3.0, `columns = vars(...)` has been deprecated.
• Please use `columns = c(...)` instead.
name sell_value buy_value category image
Royal Crown 300000 1200000 Hats
Crown 250000 1000000 Hats
Gold Armor 80000 320000 Dresses
Golden Casket 80000 320000 Furniture
Grand Piano 65000 260000 Furniture
Golden Toilet 60000 240000 Furniture
Blue Steel Staircase NA 228000 Furniture
Iron Bridge NA 228000 Furniture
Red Steel Staircase NA 228000 Furniture
Red Zen Bridge NA 228000 Furniture
Zen Bridge NA 228000 Furniture

Here’s a function.

most_expensive <- function(category_name=NULL, price_category=buy_value){
  
  if(!is.null(category_name)){
    items <- items %>%
      filter(category == category_name)
  }
  
  items %>% 
  top_n(10, {{price_category}}) %>%
  arrange(desc({{price_category}})) %>%
  select(name, sell_value, buy_value, category, image=image_url) %>%
  gt() %>%
   text_transform(
    locations = cells_body(vars(image)),
    fn = function(x) {
      web_image(
        url = x,
        height = 50
      )
    }
  )
  
}

Reproducing the above table

most_expensive()
Warning: Since gt v0.3.0, `columns = vars(...)` has been deprecated.
• Please use `columns = c(...)` instead.
name sell_value buy_value category image
Royal Crown 300000 1200000 Hats
Crown 250000 1000000 Hats
Gold Armor 80000 320000 Dresses
Golden Casket 80000 320000 Furniture
Grand Piano 65000 260000 Furniture
Golden Toilet 60000 240000 Furniture
Blue Steel Staircase NA 228000 Furniture
Iron Bridge NA 228000 Furniture
Red Steel Staircase NA 228000 Furniture
Red Zen Bridge NA 228000 Furniture
Zen Bridge NA 228000 Furniture

Most Expensive Furniture

most_expensive("Furniture")
Warning: Since gt v0.3.0, `columns = vars(...)` has been deprecated.
• Please use `columns = c(...)` instead.
name sell_value buy_value category image
Golden Casket 80000 320000 Furniture
Grand Piano 65000 260000 Furniture
Golden Toilet 60000 240000 Furniture
Blue Steel Staircase NA 228000 Furniture
Iron Bridge NA 228000 Furniture
Red Steel Staircase NA 228000 Furniture
Red Zen Bridge NA 228000 Furniture
Zen Bridge NA 228000 Furniture
Elaborate Kimono Stand 55000 220000 Furniture
Golden Seat 50000 200000 Furniture

Most Expensive Hats

library(gt)
most_expensive("Hats")
Warning: Since gt v0.3.0, `columns = vars(...)` has been deprecated.
• Please use `columns = c(...)` instead.
name sell_value buy_value category image
Royal Crown 300000 1200000 Hats
Crown 250000 1000000 Hats
Gold Helmet 50000 200000 Hats
Blue Rose Crown 12000 48000 Hats
Gold Rose Crown 12000 48000 Hats
Snowperson Head 7000 28000 Hats
Knight's Helmet 3750 15000 Hats
Dark Cosmos Crown 3360 13440 Hats
Chic Rose Crown 2880 11520 Hats
Purple Hyacinth Crown 2880 11520 Hats
Purple Pansy Crown 2880 11520 Hats
Purple Windflower Crown 2880 11520 Hats
Simple Mum Crown 2880 11520 Hats

Most Expensive Fossils

most_expensive("Fossils", sell_value)
Warning: Since gt v0.3.0, `columns = vars(...)` has been deprecated.
• Please use `columns = c(...)` instead.
name sell_value buy_value category image
Brachio Skull 6000 NA Fossils
T. Rex Skull 6000 NA Fossils
Brachio Chest 5500 NA Fossils
Brachio Tail 5500 NA Fossils
Dimetrodon Skull 5500 NA Fossils
Right Megalo Side 5500 NA Fossils
T. Rex Torso 5500 NA Fossils
Tricera Skull 5500 NA Fossils
Brachio Pelvis 5000 NA Fossils
Dimetrodon Torso 5000 NA Fossils
Diplo Skull 5000 NA Fossils
Diplo Tail 5000 NA Fossils
Left Quetzal Wing 5000 NA Fossils
Right Quetzal Wing 5000 NA Fossils
Stego Skull 5000 NA Fossils
T. Rex Tail 5000 NA Fossils
Tricera Torso 5000 NA Fossils

Priceless Items by Category

items %>%
  filter(is.na(buy_value)) %>%
  ggplot(aes(x=category)) + geom_bar() +
  theme(axis.text.x = element_text(angle=90))

library(ggalluvial)

pers_vil %>% filter(species %in% c("cat", "rabbit", "dog")) %>%
ggplot(
       aes(y = count,
           axis1 = personality, axis2 = species)) +
           geom_alluvium(aes(fill = count),
                width = 0, knot.pos = 0, reverse = FALSE) +
  guides(fill = FALSE) +
  geom_stratum(width = 1/8, reverse = FALSE) +
    geom_text(stat = "stratum", infer.label = TRUE, reverse = FALSE) 
Warning: The `<scale>` argument of `guides()` cannot be `FALSE`. Use "none" instead as
of ggplot2 3.3.4.
Warning: The parameter `infer.label` is deprecated.
Use `aes(label = after_stat(stratum))`.

Citation

BibTeX citation:
@online{laderas2020,
  author = {Laderas, Ted and Laderas, Ted},
  title = {Animal {Crossing}},
  date = {2020-05-05},
  url = {https://laderast.github.io//articles/2020-05-05_animal-crossing/animal-crossing.html},
  langid = {en}
}
For attribution, please cite this work as:
Laderas, Ted, and Ted Laderas. 2020. “Animal Crossing.” May 5, 2020. https://laderast.github.io//articles/2020-05-05_animal-crossing/animal-crossing.html.