In: Math
Please attach R code:
Use library(nycflights13) a. plot histogram for distance where carrier is "FL". Print graph(s). b. plot Two box plots side by side for distance where carrier are "FL" and “US”. Print graph(s). c. plot two histograms and two box plots in one graph where carrier are "FL" and “US”, equal scale for each box plot pair. Print graph(s).
The R code will be indented to the right.
install.packages("nycflights13")
library(nycflights13)
# This helps in installing the packages
data= nycflights13::flights
# Load the flights data
FL =subset(data,carrier=="FL")
US =subset(data,carrier=="US")
# Load only the data where carrier is FL and US
a.
hist(FL$distance,bins=10, main = "Histogram of distances of FL carrier")
# This plots the histogram required
b.
par(mfrow= c(1,2))
# Sets the graphing environment to 1x2; thus 2 plots can be plotted side by side.
boxplot(FL$distance,ylim=c(0,2500),
main= "Boxplot of distances of FL carrier")
boxplot(US$distance,ylim=c(0,2500), main= "Boxplot of distances of
US carrier")
# Gives out the required boxplots
c.
par(mfrow= c(2,2))
# Sets the environment
hist(FL$distance,bins=10, main = "Histogram of distances of FL carrier")
hist(US$distance,bins=10, main = "Histogram of distances of US carrier")
boxplot(FL$distance,ylim=c(0,2500), main= "Boxplot of distances of FL carrier")
boxplot(US$distance,ylim=c(0,2500), main= "Boxplot of distances of US carrier")
# Gives the required graphs