Year Export Import
<chr> <chr> <chr>
1 2000 79 32
2 2001 86 34
3 2002 87 32
4 2003 87 32
5 2004 98 34
6 2005 107 37
如何使用 ggplot2 在同一個圖表上繪制兩個出口進口,x 軸上是年份?
我敢肯定這很簡單,但我找不到任何例子。
uj5u.com熱心網友回復:
df <- data.frame(
Year = c(2000L, 2001L, 2002L, 2003L, 2004L, 2005L),
Export = c(79L, 86L, 87L, 87L, 98L, 107L),
Import = c(32L, 34L, 32L, 32L, 34L, 37L)
)
library(tidyverse)
df_l <- pivot_longer(df, cols = -Year)
ggplot(df_l, aes(Year, value, color = name))
geom_line()

由reprex 包于 2022-01-21 創建(v2.0.1)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/420822.html
標籤:
上一篇:設定箱線圖中方框的顏色
