【发布时间】:2020-02-13 07:01:32
【问题描述】:
我有一个数据框,保存为df,其中有两列我想绘制的点。另外,我想在情节上绘制两条线,并希望这些线有一个图例。这是我的代码:
ggplot(df, aes(x = x, y = y)) +
geom_point(color = "black", shape = 16, alpha = 1) +
scale_x_continuous(name = "x", limits = c(-5, 5)) +
scale_y_continuous(name = "y", limits = c(-5, 5)) +
geom_abline(intercept = 0, slope = 4/3, linetype = "dashed",
color = "gray40", size = 1, aes(colour = "XNULL")) +
geom_abline(intercept = 0, slope = 0, linetype = "dotted",
color = "gray40", size = 1, aes(colour = "YNULL")) +
scale_color_manual(name = "", values = c("XNULL" = "red", "YNULL" = "blue")) +
theme(panel.background = element_rect(fill = "white"),
panel.border = element_rect(colour = "black", fill = NA, size = 1),
legend.position = "bottom")
但是,当我运行它时,没有出现图例(我希望在底部显示图例)。关于我做错了什么的任何建议?我是使用 ggplot2 的新手,我在其他论坛上查找的解决方案都没有帮助。
【问题讨论】: