我尝试通过设置删除图例show.legend = FALSE。fill当变量是离散的时,它按预期工作:
library(ggplot2)
ggplot(mtcars, aes(x = mpg, y = wt, fill = factor(mpg))) +
geom_bar(stat = "identity", show.legend = FALSE)
Run Code Online (Sandbox Code Playgroud)
但是,当fill映射到连续变量时,show.legend = FALSE不会删除图例:
ggplot(mtcars, aes(x = mpg, y = wt, fill = mpg)) +
geom_bar(stat = "identity", show.legend = FALSE)
Run Code Online (Sandbox Code Playgroud)
为什么不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')
Run Code Online (Sandbox Code Playgroud)