r - 使用 show.legend = FALSE 删除图例不适用于连续美学

标签 r ggplot2

我尝试通过设置 show.legend = FALSE 来删除图例。当 fill 变量是离散的时,它按预期工作:

library(ggplot2)
ggplot(mtcars, aes(x = mpg, y = wt, fill = factor(mpg))) +
  geom_bar(stat = "identity", show.legend = FALSE)

enter image description here
但是,当 fill 映射到连续变量时,show.legend = FALSE 不会删除图例:
ggplot(mtcars, aes(x = mpg, y = wt, fill = mpg)) + 
   geom_bar(stat = "identity", show.legend = FALSE) 

enter image description here

为什么 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/

相关文章:

r - 当仅通过一个变量着色时,将两个分组变量的框分开

r - 使用 roxygen2 记录新的 "+"S3 方法时出现问题

r - 如何在 CentOS 上安装旧的 R 版本

r - R 中带有跨图图例的多面板图以及 R 中的 ggtext 和 gridtext

r - 分组条形图 : order x-axis & keep constant bar width, 以防缺少级别

R/指标/AUC : How can these numbers give an AUC of 1?

R - 转换数据时逐行导出,在某些地方添加 ""而不是其他地方,同时删除 NA

r - 在 stat_summary 中使用position_dodge 来获取平均值和置信区间?

r - 库错误(ggplot2): There is no package called 'ggplot2'

r - 使用 ggplot2 创建折线图,显示每个观察中两个变量之间的分布