【问题标题】:如何删除ggplot2中的特定图例?
【发布时间】:2022-01-23 16:59:14
【问题描述】:

我在多面 boxplot 中表示了三组(组织)和两组(治疗),我想删除“治疗”的图例,因为它已经在图中表示,并保留“治疗”的图例组织”。

box <- ggboxplot(subclusDF, x = 'Treatment', y = 'ATP4', fill = "Tissue", color = 'Tissue', palette = qualitative_hcl(3, palette = 'Dark 3'), add = 'jitter', shape = 'Treatment'  )
box <- box + labs(title= 'GHRL') + xlab(NULL) + ylab("Expression") + facet_grid(~Tissue)
box

box + theme()+
theme(
  plot.title = element_text(face = "bold", size = 12),
  legend.background = element_rect(fill = "white", size = 4, colour = "white"),
  legend.justification = c(0, 1),
  legend.title=element_text(NULL),
  legend.key = element_blank(),
  legend.position = c(0, 1),
  axis.text = (NULL),
  axis.ticks = element_line(colour = "grey70", size = 0.2),
  panel.grid.major = element_line(colour = "grey70", size = 0.2),
  panel.grid.minor = element_blank()
)
 box

【问题讨论】:

  • 最好包含您的代码,以便我们为您提供具体反馈。编辑:检查cookbook
  • 谢谢你,我想专门删除一个图例而不是另一个,所以不确定食谱是否能处理,但会再看一遍
  • 您可以尝试+ scale_shape_discrete(guide = "none"),但这是未经测试的猜测,因为我无法重现该问题。或+ guides(shape = "none").
  • 这能回答你的问题吗? Remove legend ggplot 2.2

标签: ggplot2 legend


【解决方案1】:

所以,特别是你想删除形状的图例:


box + 
guides(shape = F)

【讨论】:

    猜你喜欢
    • 2011-08-26
    • 1970-01-01
    • 2012-07-27
    • 2014-10-07
    • 1970-01-01
    • 1970-01-01
    • 2016-04-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多