#' Importing flights data from the nycflights13 dataset
#'
#' Reading from the csv file, scatter plot and arrival delays mean.
#' @export
analyze <- function(){
# retrieve data
flights <- read_csv("https://raw.githubusercontent.com/lucacerab/mrmee/master/inst/extdata/flights.csv")
aa <- flights[grepl('AA', flights$carrier), ]
# plot
p <- ggplot(aa, aes(x = dep_delay, y = arr_delay)) +
ggtitle("American Airlines arr/dep delays") +
theme(plot.title = element_text(hjust = 0.5, size = 18)) +
xlab("departure delay (mins)") +
ylab("arrival delay (mins)") +
geom_point()
# analyze
arrdelay <- aa[aa$arr_delay >= 0, ] #negative time is not delay
g <- sprintf("For American Airlines, the average arrival delay in 2013 was: %f minutes", mean(arrdelay$arr_delay , na.rm = T))
l <- list(p, g)
return(l)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.