蜜蜂箱线图

rm(list = ls())
gc()
library(ggplot2)
data(mtcars)
?mtcars
#cyl:气缸数,mpg:英里/加仑,gear:档数
ggplot(mtcars, aes(x=factor(cyl), y=mpg, fill=factor(gear), colour=factor(gear))) +
  geom_point(position = position_jitterdodge()) +
  geom_boxplot(alpha=0.5)

#install.packages("beeswarm")
library(beeswarm)
data(breast)
head(breast)
#            ER      ESR1     ERBB2 time_survival event_survival
# 100.CEL.gz neg  8.372133 13.085894            39              1
# 103.CEL.gz pos 10.559356  9.491683            97              0
# 104.CEL.gz pos 12.299905  9.599574            11              1
# 105.CEL.gz pos 10.776632  9.681747            99              0
# 106.CEL.gz pos 10.505124  9.436763            40              1
# 107.CEL.gz neg 10.377741  8.695576            94              0
beeswarm(time_survival ~ event_survival, data = breast,
         method = 'center',
         pch = 16, pwcol = as.numeric(ER),
         xlab = '', ylab = 'Follow-up time (months)',
         labels = c('Censored', 'Metastasis'))#Censored:截尾;metastasis:转移
legend('topright', legend = levels(breast$ER),
       title = 'ER', pch = 16, col = 1:2)
boxplot(time_survival ~ event_survival, 
        data = breast, add = T, names = c("",""), col="#0000ff22")
dev.off()
#png('diff_color.png',width=400*2,height=400*2,res=72*2,type='cairo-png')
beeswarm(time_survival ~ ER, data=breast,pch=16, pwcol=1+as.numeric(event_survival),xlab="",ylab="Follow-up time (months)",labels = c("ER neg", "ER pos"))
legend("topright",legend=c("yes","no"),title="Censored",pch=16,col=1:2)
dev.off()
#2.Compare the four methods for arranging points#点的组织方式可以多种,如("swarm", "center", "hex", "square")

## Generate some random data
set.seed(123)
distro <- list(runif = runif(100, min = -3, max = 3), rnorm = rnorm(100))

#png("arrange_points.png",width=600*2,height=600*2,res=72*2,type='cairo-png')
par(mfrow=c(2,2))#两行两列画布
for (m in c("swarm", "center", "hex", "square")) {
  beeswarm(distro, col = 2:3, pch = 16,method = m, 
           main = paste('method = "', m, '"', sep = ''))
}

dev.off()

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值