-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadData.R
More file actions
56 lines (47 loc) · 1.9 KB
/
Copy pathreadData.R
File metadata and controls
56 lines (47 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Quick script to read in the file
library(tidyverse)
library(RCurl) # still trying to get this one to work
library(bulkreadr) # needs to link to gmail account... which might make some people uncomfortable
# URL for the sheet
thisURL <- "https://docs.google.com/spreadsheets/d/1tlkZVdZP41NGNjXFQW84sBhe4AK0OMqjDwrS2FUgfbE/edit?gid=0#gid=0"
# doesn't work just now... probably because we're not pointing it to a .csv file
# download.file(thisURL, "temp.csv", method = 'curl')
# this works, needs to be linked to gmail... which isn't the worst thing ever
df_pokemon <- googlesheets4::read_sheet(thisURL,
sheet = "Packs - Overview")
# tidy up the data... this person has clearly never worked on a data science project
# but that's ok
theseColnames <- df_pokemon[4,2:ncol(df_pokemon)] %>%
gather(1:ncol(.),
key = "dontneed",
value = "names") %>%
pull(names) %>%
unique() %>%
unlist()
# NOTE: we should be careful about this part as it involves some hardcoding... and that could change things...
# more tidying...
theseColnames <- str_remove_all(theseColnames, " ")
theseColnames <- paste(rep(theseColnames, each = 2), c("HEAVY", "LIGHT"), sep = "_")
# get only the rows and columns we care about
df_cleaner <- df_pokemon[6:nrow(df_pokemon), 2:ncol(df_pokemon)]
colnames(df_cleaner) <- theseColnames
# make the data look nice
df_cleaner <- df_cleaner %>%
gather(everything(),
key = "temp",
value = "weight") %>%
unnest(weight) %>%
separate(temp,
into = c("packType", "weightType"),
sep = "_")
df_cleaner %>%
ggplot(aes(weight, fill = weightType)) +
geom_histogram(aes(y = after_stat(density)),
position = "dodge") +
facet_wrap(~packType,
scales = "free") +
see::scale_fill_flat()
ggsave("scratch/plots/firstPlot.png",
height = 3000,
width = 6000,
units = "px")