如何使用所有点为每个组创建箱形图,点的颜色可以手动分配 [英] How to create box plots with all points where for each group, the color of the points can be assigned manually

查看:118
本文介绍了如何使用所有点为每个组创建箱形图,点的颜色可以手动分配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据框:

 > (miR-15/16 FL,miR-15/16 FL,miR-15/16 FL,
miR- miR-15/16 FL,miR-15 / 16cKO,miR-15 / 16cKO,
miR-15 / 16cKO,miR-15 / 16cKO,miR-15 / 16cKO),
细胞/ SC / Live / CD8-,CD4 + / Foxp3-,中值,< BV421-A> ;, CD127'= c(1191L ,1325L,1089L,1154L,1147L,1735L,1441L,1455L,1560L,1623L)),
.Names = c(基因型,Cells / SC / Live / CD8- ,, CD4 + / Foxp3-,中值,< BV421-A> ;, CD127),
row.names = c(NA,-10L),class = c(tbl_df,tbl,data.frame))
MFI = c(1191,1325,1089,1154,1147,1735,1441,1455,1560,1623))

,我想制作每个点绘制每个点的盒状图(miR-15/16 FL和miR-15/16 cKO),并且包含所有的

 'miR-15/16 FL'

点被关闭的黑圈和所有的

 'miR-15/16 cKO'

点打开红色圆圈。我希望能够手动调整各组的颜色和形状/大小。


$ b

  library(ggplot2)
ggplot(data = df2,aes(x = df2 $ Genotype,y = df2 [2]))+
geom_boxplot(outlier.shape = NA)+
geom_jitter(position = position_jitter(width = 0.2),shape = 1,size = 5)+
ylim(0,max(df2 [2 ])+ 10)

但我一直无法弄清楚如何调整颜色/
$ b

 'miR-15/16 FL'

 'miR-15/16 cKO'$ b $ 


解决方案

@Balter击败了我的拳头....唯一的区别是我设置了ggplot调用之外的颜色和形状参数,以便将来进行progamatic访问。

  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 =黑色,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 = 0.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)


$ h $> $ $ (基因型= c('miR-15 / 16WT','miR-15 / 16WT','miR-15 / 16WT','miR-15 / 16WT','miR-15 / 16WT' 'miR-15 / 16WT','miR-15 / 16WT',
'miR-15 / 16cKO','miR-15 / 16cKO','miR-15 / 16cKO ,'miR-15 / 16cKO','miR-15 / 16cKO'),
MFI = c(1191,1325,1089,1154,1147,1735,1441,1455,1560,1623))
$ b color.groups <-c('miR-15/16 WT'=黑色,miR-15/16 cKO=红色)
shape.groups< (a)(x =基因型,y = MFI))的结果显示,miR-15/16 WT'= 20,miR-15/16 cKO'= 21) +
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)



Update2 :



  df2 < - 结构(列表(基因型= c(miR-15/16 FL,miR-15 / 16 FL,miR-15/16 FL,
miR-15 / 16FL,miR-15 / 16FL,miR-15 / 16cKO,miR-15 / 16cKO,
miR-15 / 16cKO miR-15 / 16cKO,miR-15 / 16cKO),
细胞/ SC / Live / CD8-,CD4 + / Foxp3-,中值,,CD127' c(基因型,细胞/ SC /活/ CD8 - ,, CD4 + / CD8 + 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)
名称(color.groups)< - 唯一(df2 $基因型)
shape.groups <-c(20,21)
名称(shape.groups)< - 唯一(df2 $基因型)

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)
pre>


I have a data frame:

> dput(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"))
MFI=c(1191,1325,1089,1154,1147,1735,1441,1455,1560,1623))

and I would like to make a boxplot with each point plotted for each group (miR-15/16 FL and miR-15/16 cKO) and have all the

'miR-15/16 FL' 

points be closed black circles and all the

'miR-15/16 cKO' 

points be open red circles. I would like to be able to manually adjust the colors and shapes/sizes of the points for each group.

So far, I have tried:

library(ggplot2)
ggplot(data=df2, aes(x = df2$Genotype, y = df2[2])) +
geom_boxplot(outlier.shape = NA) +
geom_jitter(position = position_jitter(width = .2), shape=1, size=5) +
ylim(0,max(df2[2])+10)

But I haven't been able to figure out how to adjust the colors/shapes independently for

'miR-15/16 FL'

and

'miR-15/16 cKO'

Thanks for any help with this!

解决方案

@Balter beat me to the punch.... The only difference is that I set the color and shape parameters outside the ggplot call for future progamatic access.

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)

Update:

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)

Update2:

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)

这篇关于如何使用所有点为每个组创建箱形图,点的颜色可以手动分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆