https://brickset.com/ contains data on historical lego sets as well as current sets. Unlike Lego.com, we can access Brickset data using an API (application programming interface). This does require registering for a brickset account and requesting an API key. All functions for the brickset.com data start with the brickset_ prefix.

brickset_setup() # guides you through the account setup process

Once you have your credentials, you can save them to your Rprofile using brickset_save_credentials(). This will also save the credentials as global variables.

brickset_save_credentials("your_username", "your_password", "your_api_key")

Then, you can access brickset’s data by authenticating. You may have to periodically reauthenticate depending on your internet configuration, but most functions should refresh the authentication automatically.

As with the Lego store, sets on brickset are organized by theme.

We can see what themes existed at the beginning…

Or the themes that have been around the longest…

Most of the functions described in the API documentation have been wrapped; the exception is functions which concern a user’s personal collection.

Some themes have sub-themes:

Not all themes are available in all years:

We can get sets as well, searching using the set search api: https://brickset.com/api/v2.asmx?op=getSets

brickset_auth() # At this point I had to reauthenticate
#> [1] TRUE
sets_2015 <- brickset_get_sets(year = 2015)
sets_2015
#> # A tibble: 200 x 47
#>    setid number numbervariant name   year theme themegroup subtheme pieces
#>    <dbl> <chr>  <chr>         <chr> <dbl> <chr> <chr>      <chr>     <dbl>
#>  1 24063 10246  1             Dete…  2015 Crea… Model mak… Modular…   2262
#>  2 24153 10247  1             Ferr…  2015 Crea… Model mak… Fairgro…   2464
#>  3 24154 10248  1             Ferr…  2015 Crea… Model mak… Vehicles   1158
#>  4 24156 10249  1             Wint…  2015 Crea… Model mak… Winter …    898
#>  5 24076 10581  1             Ducks  2015 Duplo Pre-school Forest …     13
#>  6 24077 10582  1             Anim…  2015 Duplo Pre-school Forest …     39
#>  7 24078 10583  1             Fish…  2015 Duplo Pre-school Forest …     32
#>  8 24079 10584  1             Fore…  2015 Duplo Pre-school Forest …    105
#>  9 23989 10585  1             Mom …  2015 Duplo Pre-school ""           13
#> 10 23990 10586  1             Ice …  2015 Duplo Pre-school ""           11
#> # … with 190 more rows, and 38 more variables: minifigs <dbl>,
#> #   image <chr>, imagefilename <chr>, thumbnailurl <chr>,
#> #   largethumbnailurl <chr>, imageurl <chr>, brickseturl <chr>,
#> #   released <chr>, owned <chr>, wanted <chr>, qtyowned <dbl>,
#> #   usernotes <chr>, acmdatacount <dbl>, ownedbytotal <dbl>,
#> #   wantedbytotal <dbl>, ukretailprice <dbl>, usretailprice <dbl>,
#> #   caretailprice <dbl>, euretailprice <dbl>, usdateaddedtosah <chr>,
#> #   usdateremovedfromsah <chr>, rating <dbl>, reviewcount <dbl>,
#> #   packagingtype <chr>, availability <chr>, instructionscount <dbl>,
#> #   additionalimagecount <chr>, agemin <dbl>, agemax <chr>, height <chr>,
#> #   width <chr>, depth <chr>, weight <chr>, category <chr>,
#> #   userrating <dbl>, ean <chr>, upc <chr>, lastupdated <chr>

Note that the setNumber parameter is not equivalent to the lego set number, it is an internal Brickset number.

We can also get reviews and instructions for a set:

The first link is here and shows the full instruction set for building a disney castle.

disney_castle_reviews <- brickset_get_reviews(disney_castle$setid)

disney_castle_reviews %>% 
  gather(key = "ratingType", value = "ratingValue", overallrating:valueformoney) %>%
  mutate(ratingValue = factor(ratingValue)) %>%
  ggplot(aes(x = ratingType, fill = ratingValue)) + 
  geom_bar(position = "stack") + 
  scale_fill_brewer(palette = "BuGn")