在R中使用ggplot2,图例不会显示在我的图中。为什么会这样?

问题描述 投票:0回答:1

View(PV)                                                                

library(ggplot2)

ssplot <- ggplot(PV, aes(x=year)) + geom_line(aes(y = infinite_horizon), color = "darkred", size = 1) + geom_line(aes(y = through_year_75), color="steelblue", size = 1)

print(ssplot + labs(y="Present Value ($, trillions)", x = "Year") + ggtitle("Measures of Unfunded Social Security Obligations, 2003-2020"))

[不幸的是,我还不能发布图像,但是我得到的是一个有两行且没有图例的图形。为什么会这样呢?任何帮助,将不胜感激。谢谢。

r ggplot2 legend linegraph
1个回答
0
投票

很难看到您的数据示例,但是像下面那样重组代码将有助于解决问题:

library(ggplot2)

ssplot <- ggplot(PV, aes(x=year)) + 
geom_line(aes(y = infinite_horizon), color = "darkred", size = 1) +
geom_line(aes(y = through_year_75), color="steelblue", size = 1) +
labs(y="Present Value ($, trillions)", x = "Year") +
ggtitle("Measures of Unfunded Social Security Obligations, 2003-2020")

ssplot
© www.soinside.com 2019 - 2024. All rights reserved.