使图例不可见,但图形尺寸和边距保持相同 [英] Make legend invisible but keep figure dimensions and margins the same

查看:46
本文介绍了使图例不可见,但图形尺寸和边距保持相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用图例作图了.

使用图像编辑程序使图例不可见(但图形的尺寸相同)

Using an image editing program I made the legend invisible (but otherwise the figure has the same dimensions)

是否可以在ggplot2中执行此操作?我想在一个文档中有一个2x2的图表面板,但是只有一个图例.

Is it possible to do this in ggplot2? I want to have a 2x2 panel of diagrams in a document but only one legend.

推荐答案

以它为例,

library(ggplot2)

p <- ggplot(mtcars, aes(x = disp, y = hp, color = factor(cyl))) +
    geom_point() +
    geom_line()

以下似乎有效:

p + theme(
        legend.text = element_text(color = "white"),
        legend.title = element_text(color = "white"),
        legend.key = element_rect(fill = "white")
    ) + 
    scale_color_discrete(
        guide = guide_legend(override.aes = list(color = "white"))
    )

请注意,灰色绘图区域的尺寸没有变化.

Notice that the dimension of the gray plot area did not change.

这篇关于使图例不可见,但图形尺寸和边距保持相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆