【问题标题】:ggrepel remove line around labelsggrepel 删除标签周围的线
【发布时间】:2017-05-31 03:11:02
【问题描述】:

如何删除geom_label_repel 周围的行。使用label.size = 0 似乎没有明显的效果。我可以设置`color

library(ggplot2)
library(ggrepel)
ggplot(mtcars, aes(wt, mpg, color = wt)) +
  geom_point(color = 'red') +
  geom_label_repel(aes(label = rownames(mtcars)), label.size = 0, fill = "white") +
  theme_classic(base_size = 16)

在空白geom_label_repel 之后输入geom_text_repel 偶尔会起作用,但并不可靠:这些框可能出现在与文本不同的位置。

【问题讨论】:

  • label.size=0 在我运行您的代码时摆脱了边界。
  • 它们是可见的,但非常小。 (例如,当我将其另存为 PDF 时,它们在某些查看器中清晰可见。)
  • 如果你做label.size=NA怎么样?

标签: r ggrepel


【解决方案1】:

正如eipi10在评论中指出的那样,设置label.size=NA

library(ggplot2)
library(ggrepel)
ggplot(mtcars, aes(wt, mpg, color = wt)) +
  geom_point(color = 'red') +
  geom_label_repel(aes(label = rownames(mtcars)), label.size = NA, fill = "white") +
  theme_classic(base_size = 16)

【讨论】:

    【解决方案2】:

    您可以使用geom_text_repel geom 省略标签框。

    library(ggplot2)
    library(ggrepel)
    g <- ggplot(mtcars, aes(wt, mpg, color = wt)) +
      geom_point(color = 'red') +
      theme_classic(base_size = 16)
    
    g + geom_label_repel(aes(label = rownames(mtcars)), fill = "white")
    

    g + geom_text_repel(aes(label = rownames(mtcars)))
    

    另外,根据帮助页面:

    目前geom_label_repel ...比geom_text_repel慢很多。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-05
      • 1970-01-01
      • 2021-04-07
      • 2019-01-30
      相关资源
      最近更新 更多