#Abrir librerias
library(tidyverse)
## āā Attaching core tidyverse packages āāāāāāāāāāāāāāāāāāāāāāāā tidyverse 2.0.0 āā
## ā dplyr 1.1.0 ā readr 2.1.4
## ā forcats 1.0.0 ā stringr 1.5.0
## ā ggplot2 3.4.1 ā tibble 3.1.8
## ā lubridate 1.9.2 ā tidyr 1.3.0
## ā purrr 1.0.1
## āā Conflicts āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā tidyverse_conflicts() āā
## ā dplyr::filter() masks stats::filter()
## ā dplyr::lag() masks stats::lag()
## ā¹ Use the ]8;;http://conflicted.r-lib.org/conflicted package]8;; to force all conflicts to become errors
library(dplyr)
library(ggplot2)
library(nycflights13)
data(flights)
view(flights)
#1. Elabora una grĆ”fica de barras que refleje el nĆŗmero de vuelos por aerolĆnea que han salido de NYC en el aƱo 2013.
bar_graph <- flights %>% select(carrier,origin, year) %>% filter(year == 2013,) %>% group_by(carrier) %>% summarise(Total=n())
ggplot(bar_graph, aes(x = carrier, y=Total) ) +
geom_bar(width = 0.8, stat='identity', fill='pink',
position = position_dodge()
)+
ggtitle("Vuelos por aerolinea NY, 2013")+
labs(x="Aerolineas", y= "# de vuelos") +
labs(fill = "")+
geom_text(aes(label=Total), vjust=1.6, color="black",
position = position_dodge(0.9), size=2.0
) +
theme_bw(base_size = 10)

#2. ObtĆ©n una tabla que indique el nĆŗmero de vuelos por aerolĆnea.
#3. Elabora una grĆ”fica de barras que refleje el nĆŗmero de vuelos por aerolĆnea que han salido de NYC en el aƱo 2013 para cada uno de los tres aeropuertos. ( John F. Kennedy, LaGuardia and Newark Liberty)
#JFK
bar_graph_JFK <- flights %>% select(carrier,origin, year) %>% filter(year == 2013,) %>% filter(origin == 'JFK')%>% group_by(carrier) %>% summarise(Total=n())
ggplot(bar_graph_JFK, aes(x = carrier, y=Total) ) +
geom_bar(width = 0.8, stat='identity', fill='skyblue',
position = position_dodge()
)+
ggtitle("Vuelos por aerolinea NY, 2013")+
labs(x="Aerolineas", y= "# de vuelos") +
labs(fill = "")+
geom_text(aes(label=Total), vjust=1.6, color="black",
position = position_dodge(0.9), size=2.0
) +
theme_bw(base_size = 10)

#LGA
bar_graph_LGA <- flights %>% select(carrier,origin, year) %>% filter(year == 2013,) %>% filter(origin == 'LGA')%>% group_by(carrier) %>% summarise(Total=n())
ggplot(bar_graph_LGA, aes(x = carrier, y=Total) ) +
geom_bar(width = 0.8, stat='identity', fill='orange',
position = position_dodge()
)+
ggtitle("Vuelos por aerolinea NY, 2013")+
labs(x="Aerolineas", y= "# de vuelos") +
labs(fill = "")+
geom_text(aes(label=Total), vjust=1.6, color="black",
position = position_dodge(0.9), size=2.0
) +
theme_bw(base_size = 10)

#EWR
bar_graph_EWR <- flights %>% select(carrier,origin, year) %>% filter(year == 2013,) %>% filter(origin == 'EWR')%>% group_by(carrier) %>% summarise(Total=n())
ggplot(bar_graph_EWR, aes(x = carrier, y=Total) ) +
geom_bar(width = 0.8, stat='identity', fill='lightgreen',
position = position_dodge()
)+
ggtitle("Vuelos por aerolinea NY, 2013")+
labs(x="Aerolineas", y= "# de vuelos") +
labs(fill = "")+
geom_text(aes(label=Total), vjust=1.6, color="black",
position = position_dodge(0.9), size=2.0
) +
theme_bw(base_size = 10)
