R Pre/Post 落线散点图

R Pre/Post Drop Lines Scatterplot

有没有办法用成对的点创建散点图。例如,我有 50 位患者的术前和术后 BMI 值。我想在一条垂直线上可视化这些点中的每一个,这样变化就很清楚了。我试过 ggpaired 函数,但这只会创建一个具有不同条件的图表。条件是一样的。

混合散点图:

我猜您的数据看起来与这个随机 患者 示例

相似
library(tidyverse)

patients <- tibble(
    id = rep(1:50, each = 2),
    group = rep(c("Placebo", "Treatment"), each = 50),
    stage = rep(c("Pre", "Post"), times = 50),
    measurement = rnorm(100)
)

patients
#> # A tibble: 100 x 4
#>       id group   stage measurement
#>    <int> <chr>   <chr>       <dbl>
#>  1     1 Placebo Pre       -0.710 
#>  2     1 Placebo Post      -1.20  
#>  3     2 Placebo Pre       -0.513 
#>  4     2 Placebo Post      -0.0675
#>  5     3 Placebo Pre       -0.346 
#>  6     3 Placebo Post       0.467 
#>  7     4 Placebo Pre        0.626 
#>  8     4 Placebo Post       0.884 
#>  9     5 Placebo Pre        0.0290
#> 10     5 Placebo Post       1.43  
#> # ... with 90 more rows

ggplot2 的简单方法是这样的

ggplot(patients, aes(id, measurement)) +
    geom_line(aes(group = id, color = group))

reprex package (v2.0.0)

于 2021-06-22 创建