按照我的数据框,使用 dput():
structure(list(year = 1984:2007, ger.90.10.ratio = c(3.1, 3.09,
2.98, 2.93, 2.98, 2.96, 2.95, 3.12, 3.16, 3.13, 3.24, 3.3, 3.28,
3.24, 3.24, 3.17, 3.23, 3.31, 3.63, 3.69, 3.75, 3.91, 4.1, 3.99
), kanzler = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L), wahljahr = c(0L,
0L, 1L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 1L, 0L, 0L,
0L, 1L, 0L, 0L, 1L, 0L, 0L), us.90.10.ratio = c(9.55, 9.69, 10.09,
10.23, 10.21, 9.99, 10.12, 10.22, 10.34, 10.64, 10.57, 10.11,
10.33, 10.6, 10.44, 10.42, 10.58, 10.63, 10.75, 11.22, 11.08,
11.17, 11.08, 11.18), us.80.20.ratio = c(4.36, 4.38, 4.49, 4.48,
4.45, 4.44, 4.42, 4.51, 4.6, 4.65, 4.68, 4.52, 4.61, 4.64, 4.65,
4.62, 4.56, 4.65, 4.69, 4.83, 4.76, 4.78, 4.84, 4.93), ger.ratio.diff = c(NA,
-0.0100000000000002, -0.11, -0.0499999999999998, 0.0499999999999998,
-0.02, -0.00999999999999979, 0.17, 0.04, -0.0300000000000002,
0.11, 0.0599999999999996, -0.02, -0.0399999999999996, 0, -0.0700000000000003,
0.0600000000000001, 0.0800000000000001, 0.32, 0.0600000000000001,
0.0600000000000001, 0.16, 0.19, -0.109999999999999), ger.ratio.change = c(0,
-0.0100000000000002, -0.11, -0.0499999999999998, 0.0499999999999998,
-0.02, -0.00999999999999979, 0.17, 0.04, -0.0300000000000002,
0.11, 0.0599999999999996, -0.02, -0.0399999999999996, 0, -0.0700000000000003,
0.0600000000000001, 0.0800000000000001, 0.32, 0.0600000000000001,
0.0600000000000001, 0.16, 0.19, -0.109999999999999)), row.names = c(NA,
-24L), .Names = c("year", "ger.90.10.ratio", "kanzler", "wahljahr",
"us.90.10.ratio", "us.80.20.ratio", "ger.ratio.diff", "ger.ratio.change"
), class = "data.frame")
我想要做的是创建一个线图,根据第三个变量的值改变线型。它应该如下图所示
用文字表示:在上面的数据框中,我想绘制 ger.90.10.ratio 与年份的关系,并根据 kanzler 列中的值更改线条的样式。
我到处搜索(也许我的 google-fu 不好?)但我真的很想知道这在 R 中是否可行。
感谢您的帮助,非常感谢!