如何破解 R 中的 grid::grob 对象来更改现有文本或添加新文本?

问题描述 投票:0回答:1

我有一组交叉点的汇总数据,我希望用 R 进行可视化。

  • A的概率:0.2
  • B的概率:0.1
  • A和B的概率:0.05
  • A或B的概率:0.29

为了可视化数据,我使用包

{eulerr}
。见下文。但是,我希望自定义情节的外观,但不知道如何破解该对象。

library(eulerr)

p1 <- 
  euler(c("A" = 0.205, "B" = 0.137, "A&B" = 0.0513)) |> 
  plot(quantities = TRUE,
       fills = list(fill = c("lavenderblush2", 
                             "lightblue2", 
                             "lightsalmon")))



p2 <-
  euler(c("A" = 0.205, "B" = 0.137, "A&B" = 0.0513)) |> 
  plot(quantities = FALSE,
       fills = list(fill = c("#9195F6", 
                             "#9195F6", 
                             "#9195F6")))


p1

p2

创建于 2024-04-25,使用 reprex v2.0.2


我知道它是一个

grid::grob
对象,因为:

grid::is.grob(p1)
# [1] TRUE

我如何调整情节的某些部分,例如:

  • p1
    值从浮点数更改为百分比:

  • p2
    之上添加标签:

r gridextra r-grid
1个回答
0
投票

无需破解:

plot(euler(c("A" = 0.205, "B" = 0.137, "A&B" = 0.0513)), 
     quantities = list(type = "percent"))

© www.soinside.com 2019 - 2024. All rights reserved.