knitr::opts_chunk$set(echo = F,
warning = F,
message = F,
fig.align = "center")
## Load the required package: tidyverse
library(tidyverse)
## Reading in the pokedex for almost 700 pokemon from github
pokedex <-
# Data set
read.csv('https://raw.githubusercontent.com/Shammalamala/DS-2870-Data-Sets/refs/heads/main/pokedex.csv') |>
# Adding a coupe of columns for later questions
mutate(
# Matching the gen number to the two main games in the franchise
debut_game = case_when(
generation == 1 ~ 'Red/Blue',
generation == 2 ~ 'Gold/Silver',
generation == 3 ~ 'Ruby/Sapphire',
generation == 4 ~ 'Diamond/Pearl',
generation == 5 ~ 'Black/White',
generation == 6 ~ 'X/Y'
),
# Adding a column to indicate which of the 'main types' a pokemon is, if any
main_type = case_when(
type1 == 'Grass' | type2 == 'Grass' ~ 'Grass',
type1 == 'Water' | type2 == 'Water' ~ 'Water',
type1 == 'Fire' | type2 == 'Fire' ~ 'Fire',
type1 == 'Bug' | type2 == 'Bug' ~ 'Bug',
type1 == 'Normal' ~ 'Normal',
.default = 'Other'
) |> factor(levels = c('Fire', 'Water', 'Grass', 'Bug', 'Normal', 'Other')),
# Changing legendary to be 'Legendary'/'Not Legendary' instead of T/F
legendary = if_else(legendary, 'Legendary', 'Not Legendary'),
# Changing hectograms to ounces and deimeters to inches
weight = weight * 3.5274,
height = height * 3.93701
)
The pokedex data set has the information on 697 Pokemon up to generation 6 (X & Y). The relevant columns for this assignment are:
number
: the unique identifier for the pokemon in the
data setname
: the name of the pokemontype1
and type2
: Which of 17 different
types a pokemon can be (many have two types)assessed_value
: The value of the property assessed by
the town for tax purposeshp
, attack
, defense
,
sp_atk
, sp_def
, and speed
: the
base combat attributesgeneration
and debut_game
: Which game the
pokemon debuted in.height
and weight
: The size of each
pokemon (in inches and ounces, respectively)sprites
: a url to an image of each pokemon in sprite
formmain_type
: Which of the 5 most common types
(Water/Grass/Fire/Bug/Normal/Other) a pokemon is based on
type1
or type2
Create a bar chart for each generation 1 - 6. See what it should look like in Brightspace
Use the following vectors in the appropriate function to
match the bar colors:
fill = c('#ff1111', '#daa520', '#a00000', '#aaaaff', '#444444', '#6376b8')
color = c('#1111ff', '#c0c0c0', '#0000a0', '#ffaaaa', '#e1e1e1', '#ed5540')
Create the graph seen in question 2 in Brightspace. The color codes for each type are:
'Normal' = '#a8a77a',
'Grass' = '#7ac74c',
'Water' = '#6390F0',
'Fire' = '#EE8130',
'Bug' = '#a6b91a',
'Other' = '#6f35fc'
Which games had a fewest Fire types introduced as a percentage of new pokemon?
Create the graph seen in Brightspace for a histogram of weight. There should be 20 bars in the histogram
Create the graph of seen in Brightspace.
Recreate the graph from the previous question, but include
y = after_stat(count)
inside of
aes()
.
What is shown when displaying the count on the y-axis instead of the density?
Use the data set rare_types_by_generation
created in the code chunk below. It contains the number (n
)
of the four rarest pokemon types (Ghost, Fairy, Ice, Dragon) that
debuted in each generation.
## generation debut_game type n
## 1 1 Red/Blue Ghost 3
## 2 2 Gold/Silver Ghost 1
## 3 3 Ruby/Sapphire Ghost 6
## 4 4 Diamond/Pearl Ghost 7
## 5 5 Black/White Ghost 9
## 6 6 X/Y Ghost 4
## 7 1 Red/Blue Fairy 4
## 8 2 Gold/Silver Fairy 8
## 9 3 Ruby/Sapphire Fairy 5
## 10 4 Diamond/Pearl Fairy 1
## 11 5 Black/White Fairy 2
## 12 6 X/Y Fairy 12
## 13 1 Red/Blue Ice 5
## 14 2 Gold/Silver Ice 5
## 15 3 Ruby/Sapphire Ice 6
## 16 4 Diamond/Pearl Ice 6
## 17 5 Black/White Ice 7
## 18 6 X/Y Ice 4
## 19 1 Red/Blue Dragon 3
## 20 2 Gold/Silver Dragon 1
## 21 3 Ruby/Sapphire Dragon 9
## 22 4 Diamond/Pearl Dragon 5
## 23 5 Black/White Dragon 10
## 24 6 X/Y Dragon 8
Create the line graph for each type introduced in each generation. You can find what it should look like in Brightspace.
The hexcolors for each of the four types are:
'Dragon' = '#6f35fc',
'Fairy' = '#d685ad',
'Ghost' = '#000000',
'Ice' = '#96d9d6'
Also, include
scale_x_discrete(expand = c(0, 0.25))
to have the x-axis
margins match what is seen in Brightspace
The package ggimage
has a function called
geom_image()
that works like geom_point()
, but
needs one additional aesthetic: image
, which you give a
column that has either a file path (if the images are on your computer)
or url (if the image is found online).
The example below will display the attack and defense for the three original starter pokemon and their evolutions plus the original legendary pokemon:
geom_image()
can be pretty handy if you can either
create a column with the image location (like we did here) or if the
data set has the url in it already (the nflfastR
package
has a data set called teams_colors_logos
that has the url
of each team’s logo).