重命名 facet_wrap 上的图例标题
Rename Legend title on facet_wrap
我有 8 个图的小平面环绕,我想重命名图例,它目前默认为填充值 Depth_bins,但我希望能够更改它。我尝试了各种方法,包括下面使用 scale_color_discrete 的方法,但没有改变标题。我假设这是因为它是 facet_wrap.
facet_8 <- ggplot(am_dives, aes(x = st_hr, fill = Depth_bins)) +
geom_density(aes(y = ..count../sum(..count..)), position = "stack", alpha = 0.7) +
scale_x_datetime(date_labels = "%H:%M") +
labs(x = "Start hour", y = "Density") +
facet_wrap(~ID, dir = "v", scales = "free_y") +
scale_color_discrete(name = "Depth Bins")
facet_8
非常感谢任何帮助!
我认为 labs
函数应该像这里提到的那样工作:
How to change legend title in ggplot
所以,像这样:
facet_8 <- ggplot(am_dives, aes(x = st_hr, fill = Depth_bins)) +
geom_density(aes(y = ..count../sum(..count..)), position = "stack", alpha = 0.7) +
scale_x_datetime(date_labels = "%H:%M") +
labs(x = "Start hour", y = "Density") +
facet_wrap(~ID, dir = "v", scales = "free_y") +
labs(fill = "Your Title Here")
facet_8
我有 8 个图的小平面环绕,我想重命名图例,它目前默认为填充值 Depth_bins,但我希望能够更改它。我尝试了各种方法,包括下面使用 scale_color_discrete 的方法,但没有改变标题。我假设这是因为它是 facet_wrap.
facet_8 <- ggplot(am_dives, aes(x = st_hr, fill = Depth_bins)) +
geom_density(aes(y = ..count../sum(..count..)), position = "stack", alpha = 0.7) +
scale_x_datetime(date_labels = "%H:%M") +
labs(x = "Start hour", y = "Density") +
facet_wrap(~ID, dir = "v", scales = "free_y") +
scale_color_discrete(name = "Depth Bins")
facet_8
非常感谢任何帮助!
我认为 labs
函数应该像这里提到的那样工作:
How to change legend title in ggplot
所以,像这样:
facet_8 <- ggplot(am_dives, aes(x = st_hr, fill = Depth_bins)) +
geom_density(aes(y = ..count../sum(..count..)), position = "stack", alpha = 0.7) +
scale_x_datetime(date_labels = "%H:%M") +
labs(x = "Start hour", y = "Density") +
facet_wrap(~ID, dir = "v", scales = "free_y") +
labs(fill = "Your Title Here")
facet_8