简体   繁体   中英

Can't make a ggplot with multiple lines, geom_line()

I'm trying to plot two lines using flight data I gathered. My problem is that after trying different formulas, R is still only showing one line. I've separated my data according to regions (see image below). Can someone help me out with my formula?

If you need any additional information don't hesitate to ask, this is my first time posting on this channel.

ggplot(ica.vs.total, aes(x = Year, y = flights)) +
  geom_line(aes(color = region, group = region), size = 1) +
  theme_minimal()

按地区划分的航班数据

运行上述代码时的结果

When I enter :

library(ggplot2)
ica.vs.total = data.frame(flights=c(215947,197757,185782,201023,279218,261045,213343,205609),
                          region=c('TotalFlights','TotalFlights','TotalFlights','TotalFlights',
                          'TotalFlightsICA','TotalFlightsICA','TotalFlightsICA','TotalFlightsICA'),
                          Year=c(2008,2009,2010,2011,2000,2001,2002,2003))

g = ggplot(ica.vs.total, aes(x = Year, y = flights)) +
    geom_line(aes(color = region, group = region), size = 1)+
    theme_minimal()
print(g)

I get the expected result :

在此处输入图像描述

Double check your code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM