drop = true在传奇中显示未使用的级别,但没有意义[重复]

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

GGPLOT更改了它如何处理级别而没有数据,我无法获得我想要的绘图
第三个图显示了传说中未使用的级别,但没有任何意义。 我想生成第三个图,以便它具有与第一个图
的传说相同的传说 (请注意,指定颜色具有相同的行为)

scale_color_manual

它看起来似乎不是超直觉,但是尝试在层中启用
r ggplot2 legend factors
1个回答
0
投票

show.legend


您可以检查

library(ggplot2) ggplot(diamonds |> dplyr::filter(cut != "Fair"), aes(x, y, color = cut)) + geom_point(show.legend = TRUE) + scale_color_discrete(drop = FALSE)

?ggplot2::discrete_scale
arg)以获取详细信息,还可以检查https://www.tidyverse.org/blog/2024/02/ggplot2-3-5-5-5-0-0-legends/#awareness/
	
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.