我尝试通过设置 show.legend = FALSE
来删除图例。当 fill
变量是离散的时,它按预期工作:
library(ggplot2)
ggplot(mtcars, aes(x = mpg, y = wt, fill = factor(mpg))) +
geom_bar(stat = "identity", show.legend = FALSE)
但是,当
fill
映射到连续变量时,show.legend = FALSE
不会删除图例:ggplot(mtcars, aes(x = mpg, y = wt, fill = mpg)) +
geom_bar(stat = "identity", show.legend = FALSE)
为什么
show.legend = FALSE
不省略连续比例的图例?我该如何解决这个问题?我有
ggplot2 v.2.0.0
(作者:Hadley Wickham)引用:http://docs.ggplot2.org/current/geom_bar.html
最佳答案
对于您的示例案例,您可以使用 theme()
ggplot(mtcars, aes(mpg, wt, fill = mpg)) +
geom_bar(stat = "identity") +
theme(legend.position = 'none')
关于r - 使用 show.legend = FALSE 删除图例不适用于连续美学,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35784749/