在guide_legend中使用label = FALSE删除图例标签,或在discrete_scale中使用labels = NULL

Hen*_*rik 7 r ggplot2

作为一个带有几个传说的更复杂情节的一部分,其中一个传说只有一个条目.我想从此特定图例中删除标签,并仅保留(已编辑)标题.

df <- data.frame(x = 1, y = 1)

p <- ggplot(df, aes(x = x, y = y, color = factor(x))) + 
       geom_point()
p
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

因为我使用了对传说的其他操作guides(foo = guide_legend(override.aes,我希望guide_legend使用label参数删除同一调用中的标签.

来自?guide.legend:
" label:[...]如果FALSE那时标签是不可见的."

因此,我试过:

p + guides(color = guide_legend(title = "other",
                                label = FALSE))
Run Code Online (Sandbox Code Playgroud)

但是这给出了一个错误:

# Error in (function (name)  : grob 'NULL' not found
Run Code Online (Sandbox Code Playgroud)

然后我看了一下discrete_scale,它有一个labels参数(现在有一个"s").来自?discrete_scale:
" labels:NULL没有标签."

因此,我试过:

p + scale_color_discrete(name = "other",
                         labels = NULL)
Run Code Online (Sandbox Code Playgroud)

...会产生错误:

# Error in data.frame(values = scale_map(scale, breaks), labels = I(scale_labels(scale)),  : 
#                      arguments imply differing number of rows: 1, 0
Run Code Online (Sandbox Code Playgroud)

我目前的解决方法是:

p + scale_color_discrete(name = "other",
                         labels = "")
Run Code Online (Sandbox Code Playgroud)

但是,如上所述,我更愿意使用guide_legendcall 删除标签.

所以我的主要问题是:
如何让我label = FALSEguide_legend工作?

如果答案是" 它只是不起作用 ",那么" labels:NULL没有标签" 是怎样的.应该用在scale_foo_bar哪?

Hen*_*rik 1

in和inlabel = FALSE都在开发版本中被修复。guide_legendlabels = NULLdiscrete_scaleggplot2_1.0.1.9002

# install development version, see https://github.com/hadley/ggplot2/.
# install.packages("devtools")
devtools::install_github("hadley/scales")
devtools::install_github("hadley/ggplot2movies")
devtools::install_github("hadley/ggplot2")

p + guides(color = guide_legend(title = "other", label = FALSE))
# or:
# p + scale_color_discrete(name = "other", labels = NULL)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述