问题描述
我的问题是我的ggplot()
的图例没有出现.这是我的代码:
I have a problem where the legend of my ggplot()
does not appear. Here's my code:
plot_bt <- ggplot(NULL, aes(x, v1)) +
geom_line(data = nig_bt_1, colour = "black") +
geom_line(data = nig_bt_2, colour = "blue") +
geom_line(data = nig_bt_3, colour = "red") +
labs(x = "X", y = "Probability")
我试图在此图中创建图例,但我做不到.它只是没有出现.我尝试绘制三种不同类型的NIG分布图.在nig_bt_1等中,我有我的值.这三个密度出现了,但图例没有出现.我也尝试了scale_color_manual
函数,但没有成功.
I tried to make a legend inside this graph but I could not do it. It just does not appear. I try to make a plot of three different types of NIG distribution. In nig_bt_1 etc. I have my values. Those three densities appear but the legend doesn't. I tried the scale_color_manual
function too with no success.
非常感谢您.
x <- seq(-7.5,7.5,0.001)
nig_bt_1 <- data.frame(x ,v1 = dnig(x, param = pr_bt_1))
nig_bt_2 <- data.frame(x ,v1 = dnig(x, param = pr_bt_2))
nig_bt_3 <- data.frame(x ,v1 = dnig(x, param = pr_bt_3))
推荐答案
只需执行以下操作:
plot_bt <- ggplot(NULL, aes(x, v1)) +
geom_line(data = nig_bt_1, aes(colour = "a")) +
geom_line(data = nig_bt_2, aes(colour = "b")) +
geom_line(data = nig_bt_3, aes(colour = "c")) +
labs(x = "X", y = "Probability") +
scales_color_manual(values= c("a" = "black", "b" = "blue", "c" = "red"))
指南只能描述您使用aes
定义的映射. ggplot2方法当然是首先合并数据并使用分组变量.
A guide can only depict mappings you've defined using aes
. The ggplot2 way is of course to first combine the data and use a grouping variable.
这篇关于ggplot2中的其他图例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!