-
Notifications
You must be signed in to change notification settings - Fork 0
/
lego-sets.r
49 lines (41 loc) · 1.37 KB
/
lego-sets.r
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
library(devtools)
install_github("seankross/lego")
library(lego)
library(dplyr)
library(tidyverse)
library(ggplot2)
df <- dplyr::tbl_df(legosets)
legosets %>%
filter(!is.na(GBP_MSRP)) %>%
group_by(Year) %>%
ggplot(aes(Pieces)) +
geom_bar()
avg_price_per_year <- legosets %>%
filter(!is.na(USD_MSRP)) %>%
group_by(Year) %>%
do(data.frame(Price = mean(.$USD_MSRP)))
med_price_per_year <- legosets %>%
filter(!is.na(USD_MSRP)) %>%
group_by(Year) %>%
do(data.frame(Price = median(.$USD_MSRP)))
plot(avg_price_per_year, type = "l", col = "blue",
main = "Lego set prices over time", ylim = c(0, max(avg_price_per_year$Price)))
points(med_price_per_year, type = "l", col = "red")
legend("topleft", inset=c(0.2,0), legend=c("Average","Median"), lty=c(1,1), col=c("blue", "red"))
# By Year
legosets %>%
select(Item_Number,Name,Theme, GBP_MSRP, Pieces, Year) %>%
filter(GBP_MSRP > 30) %>%
filter(Pieces > 100) %>%
filter(Theme == 'Star Wars') %>%
mutate(price_per_piece = GBP_MSRP / Pieces) %>%
ggplot(aes(x=GBP_MSRP, y=price_per_piece)) +
geom_point(aes(color = Year))
# By Availability Type
legosets %>%
select(Item_Number,Name,Theme, GBP_MSRP, Pieces, Availability) %>%
filter(GBP_MSRP > 50) %>%
filter(Pieces > 100) %>%
#mutate(price_per_piece = GBP_MSRP / Pieces) %>%
ggplot(aes(x=GBP_MSRP, y=Pieces)) +
geom_point(aes(color = Availability))