1 圆角条形

Code
library(ggforce)

df <- data.frame(trt = c("a", "b", "c"), outcome = c(2.3, 1.9, 3.2))

width <- .9

df <- df |>
    mutate(trt = factor(trt)) |>
    dplyr::reframe(
        data.frame(
            x = rep(as.numeric(trt) + width / 2 * c(-1, 1), each = 2), # 指定条形图四个角的坐标
            outcome = c(c(0, outcome), rev(c(0, outcome)))
        ),
        .by = trt
    )
df
#>    trt    x outcome
#> 1    a 0.55     0.0
#> 2    a 0.55     2.3
#> 3    a 1.45     2.3
#> 4    a 1.45     0.0
#> 5    b 1.55     0.0
#> 6    b 1.55     1.9
#> 7    b 2.45     1.9
#> 8    b 2.45     0.0
#> 9    c 2.55     0.0
#> 10   c 2.55     3.2
#> 11   c 3.45     3.2
#> 12   c 3.45     0.0

ggplot(df, aes(x, outcome, fill = trt)) +
    geom_shape(radius = .05) 

Back to top