plot5 <- ggplot(df, aes(year, pollution)) +
geom_point() +
geom_line() +
labs(x = "Year", y = "Particulate matter emissions (tons)", title = "Motor vehicle emissions in Baltimore")
得到错误:
geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?
您只需将group = 1添加到ggplot或geom_line aes()中。
对于折线图,必须对数据点进行分组,以便知道要连接的点。在这种情况下,它很简单 - 所有点都应该连接,所以group = 1。当使用更多变量并绘制多行时,行的分组通常由变量完成。
��