create a stacked bar with the geom_bar() of the "carrier" variable in nycflights in r

To create a stacked bar plot with the geom_bar() of the "carrier" variable in nycflights, we can use the fill argument in addition to the aes() function.

Here is the code to create the plot:

main.r
library(nycflights13)
library(ggplot2)

ggplot(data = flights, aes(x = year, fill = carrier)) + 
  geom_bar()
110 chars
6 lines

This will create a stacked bar plot of the "carrier" variable in the flights dataset, where the bars will be stacked according to the number of flights per year by each carrier. The fill argument determines what variable will be used to define the different colors of the bars in the plot.

related categories

gistlibby LogSnag