5

我正在使用以下数据框:

df1 <- structure(list(Genotype = structure(c(1L, 1L, 1L, 1L, 1L,
2L,2L,2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L,
1L,1L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L),
.Label= c("miR-15/16 FL", "miR-15/16 cKO"), class = "factor"), 
Tissue = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
4L), .Label = c("iLN", "Spleen", "Skin", "Colon"), class = "factor"), 
`Cells/SC/Live/CD8—,, CD4+/Foxp3+,Median,<BV421-A>,CD127` = c(518L, 
715L, 572L, 599L, 614L, 881L, 743L, 722L, 779L, 843L, 494L, 
610L, 613L, 624L, 631L, 925L, 880L, 932L, 876L, 926L, 1786L, 
2079L, 2199L, 2345L, 2360L, 2408L, 2509L, 3129L, 3263L, 3714L, 
917L, NA, 1066L, 1059L, 939L, 1269L, 1047L, 974L, 1048L, 
1084L)),
.Names = c("Genotype", "Tissue", "Cells/SC/Live/CD8—,,CD4+/Foxp3+,Median,<BV421-A>,CD127"),
row.names = c(NA, -40L), class = c("tbl_df", "tbl", "data.frame"))

并尝试使用 ggplot2 绘制图,其中箱形图和点按“组织”分组并按“基因型”交错显示。这似乎运作良好,但是,我注意到在我的传说中,有一个额外的“a”被形状覆盖。

library(ggplot2)
library(ggpubr)
color.groups <- c("black","red")
names(color.groups) <- unique(df1$Genotype)
shape.groups <- c(16, 1)
names(shape.groups) <- unique(df1$Genotype)

ggplot(df1, aes(x = Tissue, y = df1[3], color = Genotype, shape = Genotype)) +
  geom_boxplot(position = position_dodge(), outlier.shape = NA) +
  geom_point(position=position_dodge(width=0.75)) +
  ylim(0,1.2*max(df1[3], na.rm = TRUE)) +
  ylab('MFI CD127 (of CD4+ Foxp3+ T cells') +
  scale_color_manual(values=color.groups) +
  scale_shape_manual(values=shape.groups) +
  theme_bw() + theme(panel.border = element_blank(), panel.grid.major = element_blank(),
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black"),
                     axis.title.x=element_blank(), aspect.ratio = 1,
                     text = element_text(size = 9)) +
  stat_compare_means(label = 'p.format', method = 't.test',
                     label.y = c(0.1*max(df1[3], na.rm = TRUE) + max(df1[3][c(1:10),], na.rm = TRUE),
                                 0.1*max(df1[3], na.rm = TRUE) + max(df1[3][c(11:20),], na.rm = TRUE),
                                 0.1*max(df1[3], na.rm = TRUE) + max(df1[3][c(21:30),], na.rm = TRUE),
                                 0.1*max(df1[3], na.rm = TRUE) + max(df1[3][c(31:40),], na.rm = TRUE)))

在此处输入图像描述

如果我隐藏 scale_color_manual 图例,它会删除“a”,但也会从图例中删除颜色。我错过了什么吗?

谢谢你的帮助!

4

0 回答 0