SpaceX - An R API wrapper for the SpaceX project

Project Status: Active – The project has reached a stable, usable state and is being actively developed.

knitr::opts_chunk$set(collapse = TRUE,
                      comment = "##",
                      fig.retina = 2,
                      fig.align = "center",
                      fig.path = "README_figs/README-")

Installation

Until now the package is not on CRAN but you can download it via GitHub with the following command:

if (!require("devtools"))
  install.packages("devtools")
devtools::install_github("JohannesFriedrich/SpaceX")

Introduction

The R-package SpaceX is an API wrapper for data collected by https://api.spacexdata.com/v3/ (version v3). You can request available data with different functions:

Function name | Description | Example --------------------|----------------------------------------------------| ------- get_SpaceX_capsules() | request information on capsules | get_SpaceX_capsules("upcoming") get_SpaceX_cores() | request information on cores | get_SpaceX_cores(core_serial = "B1037") get_SpaceX_dragons() | request information on dragon capsules | get_SpaceX_dragons("dragon1") get_SpaceX_history() | request information on SpaceX history | get_SpaceX_history() get_SpaceX_info() | request common information on SpaceX | get_SpaceX_info() get_SpaceX_landpads() | request information on landpads | get_SpaceX_landpads(id = "LZ-4") get_SpaceX_launches() | request information on launches | get_SpaceX_launches(launch_year = 2020) get_SpaceX_launchpads() | request information on launchpads | get_SpaceX_launchpads(site_id = "ksc_lc_39a") get_SpaceX_missions() | request information on missions | get_SpaceX_missions() get_SpaceX_payloads() | request information on payloads | get_SpaceX_payloads() get_SpaceX_rockets() | request information on rockets | get_SpaceX_rockets("falcon1") get_SpaceX_ships() | request information on ships | get_SpaceX_ships() get_SpaceX_roadster() | request information on SpaceX roadster | get_SpaceX_roadster()

Request basic information from SpaceX API

First we load some needed packages. The function get_SpaceX_info() will deliver some information about the company.

library(SpaceX)
library(ggplot2)
library(dplyr)

info <- get_SpaceX_info()
info
knitr::kable(
  info[,1:7],
  format = "html"
)

Request upcoming starts

upcoming <- get_SpaceX_launches("upcoming")
knitr::kable(upcoming[1:3,1:9],
             format = "html")

Play around with data

get_SpaceX_launches() %>% 
ggplot() + 
  geom_bar(aes(launch_year, fill = launch_site$site_name)) +
  facet_grid(rocket$rocket_name~launch_success, scales = "free_x") +
  theme(legend.position = "bottom") + 
  scale_fill_discrete(name = "Launch Site") +
  labs(x = "Year", y = "Counts") +
  theme(legend.position = "bottom",
        axis.text.x = element_text(angle = 45, hjust = 1))

Now we request some data about the used rockets. This can be done with the function get_SpaceX_rockets().

rockets <- get_SpaceX_rockets()
knitr::kable(rockets[,1:9],
             format = "html")

Stats 2020

stats_2020 <- get_SpaceX_launches(launch_year = 2020)
launchpads <- get_SpaceX_launchpads()

library(leaflet)
library(htmltools)

leaflet(launchpads) %>%
  addProviderTiles(providers$OpenStreetMap) %>% 
  addTiles() %>%  
  addMarkers(~location$long, ~location$lat, popup = ~htmltools::htmlEscape(location$name))

Missions

missions <- get_SpaceX_missions()
knitr::kable(missions[,1:3],
             format = "html")

SpaceX support ships

ship <- get_SpaceX_ships(active = "true")
knitr::kable(ship[1:4,1:7],
             format = "html")

Related projects



JohannesFriedrich/SpaceX documentation built on Jan. 5, 2021, 1:57 a.m.