1 点图

1.1 散点图 Scatterplot

Code
library(tidyverse)
#> Warning: package 'purrr' was built under R version 4.5.2
#> Warning: package 'stringr' was built under R version 4.5.2
#> Warning: package 'forcats' was built under R version 4.5.2
#> ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
#> ✔ dplyr     1.1.4     ✔ readr     2.1.6
#> ✔ forcats   1.0.1     ✔ stringr   1.6.0
#> ✔ ggplot2   4.0.1     ✔ tibble    3.3.0
#> ✔ lubridate 1.9.4     ✔ tidyr     1.3.1
#> ✔ purrr     1.2.0     
#> ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
#> ✖ dplyr::filter() masks stats::filter()
#> ✖ dplyr::lag()    masks stats::lag()
#> ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
ToothGrowth$dose <- as.factor(ToothGrowth$dose)
p <- ggplot(data = ToothGrowth, aes(x=dose, y=len)) + 
    geom_point()
p

1.2 Dotplot

  • Cleveland 点图

  • Strip Plot 带状点图

1.2.1 geom_dotplot()

Code

# 点图
p1 <- ggplot(ToothGrowth, aes(x=dose, y=len)) + 
  geom_dotplot(binaxis='y', binwidth = 0.4,stackdir='center',
               stackratio=1.5, dotsize=1.2)


p2<- p1 + stat_summary(fun=median, geom="point", shape=18,
                 size=3, color="red")

library(patchwork)
#> Warning: package 'patchwork' was built under R version 4.5.2
p1+p2

1.2.2 ggpubr::ggdotplot()

Code
library(ggpubr)
#> Warning: package 'ggpubr' was built under R version 4.5.2
library(readxl)
f6d <-
    read_excel("data/01source.xlsx", sheet = "Fig.6", range = "D2:E18")
f6d |> pivot_longer(
    cols = everything(),
    names_to = "status",
    values_to = "Ratio",
) |> 
    tidyr::drop_na() ->f6d
Code
ggdotplot(f6d,
          x="status",
          y="Ratio",
          add =c("mean_sd"),
          color = "status",
          fill = "status",
          error.plot = "errorbar",
          binwidth = 0.2
)+
    geom_signif(
        comparisons = list(c("relapse","non-relapse")),
    )+
    
    stat_summary(
        fun.data = "mean_sd",geom = "pointrange",linewidth=.3
    )+
    ggplot2::annotate(
        geom="segment",
        x=0.9,
        xend=1.1,
        y=2.42019873,#均值
    )+
    ggplot2::annotate(
        geom="segment",
        x=1.9,
        xend=2.1,
        y=0.789463173,#均值
    )

1.3 蜂群图

Beeswarm plots

Code
# library(ggbeeswarm)
Back to top