• 主页
  • 在ggplot中未显示线条

在ggplot中未显示线条

我有以下数据帧data。我正在尝试使用ggplot创建折线图,其中有两条线(Date下的两个日期),Key作为我的x轴,Value作为我的Y轴。

structure(list(Date = c("2020-11-01", "2020-11-28", "2020-11-01", 
"2020-11-28", "2020-11-01", "2020-11-28", "2020-11-01", "2020-11-28", 
"2020-11-01", "2020-11-28", "2020-11-01", "2020-11-28", "2020-11-01", 
"2020-11-28"), Key = structure(c(1L, 1L, 2L, 2L, 3L, 3L, 4L, 
4L, 5L, 5L, 6L, 6L, 7L, 7L), .Label = c("3M", "2YR", "5YR", "10YR", 
"20YR", "25YR", "30YR"), class = "factor"), Value = c(3.6, 4.25, 
4.22, 4.37, 7.09, 7.065, 9.315, 8.96, 11.65, 11.05, 11.77, 11.145, 
11.73, 11.075)), row.names = c(NA, -14L), class = "data.frame")

这是我在绘图中使用的代码。然而,它并没有像预期的那样出现(曲线没有出现在绘图上,添加了下面的图像)

ggplot(dat2, aes(x = Key, y = Value, col = Date)) +
  geom_line()

?

?

这就是我希望它看起来像这样

?

?

转载请注明出处:http://www.jxbyjx.net/article/20230504/2225007.html