@Balter 击败了我……唯一的区别是我在 ggplot 调用之外设置了颜色和形状参数,以便将来进行程序访问。
library(ggplot2)
df2 <- data.frame(Genotype = c('WT','WT','WT','WT','WT',
'cKO','cKO','cKO','cKO','cKO'),
MFI=c(1191,1325,1089,1154,1147,1735,1441,1455,1560,1623))
color.groups <- c(WT="black", cKO="red")
shape.groups <- c(WT=20, cKO=21)
ggplot(data=df2, aes(x = df2$Genotype, y = df2$MFI)) +
geom_boxplot(outlier.shape = NA) +
geom_point(position = position_jitter(width = .2), size=5,
aes(color=Genotype, shape = Genotype)) +
ylim(0,max(df2$MFI)+10) +
scale_color_manual(values=color.groups) +
scale_shape_manual(values=shape.groups)
更新:
library(ggplot2)
df2 <- data.frame(Genotype = c('miR-15/16 WT','miR-15/16 WT','miR-15/16 WT','miR-15/16 WT','miR-15/16 WT',
'miR-15/16 cKO','miR-15/16 cKO','miR-15/16 cKO','miR-15/16 cKO','miR-15/16 cKO'),
MFI=c(1191,1325,1089,1154,1147,1735,1441,1455,1560,1623))
color.groups <- c(`miR-15/16 WT`="black", `miR-15/16 cKO`="red")
shape.groups <- c(`miR-15/16 WT`=20, `miR-15/16 cKO`=21)
ggplot(data=df2, aes(x = Genotype, y = MFI)) +
geom_boxplot(outlier.shape = NA) +
geom_point(position = position_jitter(width = .2), size=5,
aes(color=Genotype, shape = Genotype)) +
ylim(0,max(df2$MFI)+10) +
scale_color_manual(values=color.groups) +
scale_shape_manual(values=shape.groups)
更新2:
df2 <- structure(list(Genotype = c("miR-15/16 FL", "miR-15/16 FL", "miR-15/16 FL",
"miR-15/16 FL", "miR-15/16 FL", "miR-15/16 cKO", "miR-15/16 cKO",
"miR-15/16 cKO", "miR-15/16 cKO", "miR-15/16 cKO"),
`Cells/SC/Live/CD8—,, CD4+/Foxp3-,Median,<BV421-A>,CD127` = c(1191L, 1325L, 1089L, 1154L, 1147L, 1735L, 1441L, 1455L, 1560L, 1623L)),
.Names = c("Genotype", "Cells/SC/Live/CD8—,, CD4+/Foxp3-,Median,<BV421-A>,CD127"),
row.names = c(NA, -10L), class = c("tbl_df", "tbl", "data.frame"))
colnames(df2) <- c("Genotype", "MFI")
color.groups <- c("black","red")
names(color.groups) <- unique(df2$Genotype)
shape.groups <- c(20, 21)
names(shape.groups) <- unique(df2$Genotype)
ggplot(data=df2, aes(x = Genotype, y = MFI)) +
geom_boxplot(outlier.shape = NA) +
geom_point(position = position_jitter(width = .2), size=5,
aes(color=Genotype, shape = Genotype)) +
ylim(0,max(df2$MFI)+10) +
scale_color_manual(values=color.groups) +
scale_shape_manual(values=shape.groups)