# R绘图基础（8）点柱图(dot histogram)

 英文名称 中文名称 bar 条形图 line 线图 area 面积图 pie 饼图 high-low 高低图 pareto 帕累托图 control 控制图 boxplot 箱线图 error bar 误差条图 scatter 散点图 P-P P-P正态概率图 Q-Q Q-Q正态概率图 sequence 序列图 ROC Curve ROC分类效果曲线图 Time Series 时间序列图

```> require(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 > require(plotrix) > cluster<-cluster.overplot(breast\$event_survival, breast\$time_survival) > png("dothist.png",width=1000,height=1000) > opar<-par(mfrow=c(3,3)) > plot (breast\$event_survival, breast\$time_survival, main="Multiple points on coordinate",col=as.numeric(breast\$ER),xaxt="n",xlim=c(-1,2)) > axis(1,at=c(0,1),labels=c("Censored","Metastasis")) > plot(jitter(breast\$event_survival), breast\$time_survival, main="Using Jitter on x-axis",col=as.numeric(breast\$ER),xaxt="n",xlim=c(-0.5,1.5)) > axis(1,at=c(0,1),labels=c("Censored","Metastasis")) > plot(jitter(breast\$event_survival), jitter(breast\$time_survival), main="Using Jitter on x and y-axis",col=as.numeric(breast\$ER),xaxt="n",xlim=c(-0.5,1.5)) > axis(1,at=c(0,1),labels=c("Censored","Metastasis")) > sunflowerplot(breast\$event_survival, breast\$time_survival, main="Using Sunflowers",xaxt="n",xlim=c(-0.5,1.5)) > axis(1,at=c(0,1),labels=c("Censored","Metastasis")) > plot(cluster, main="Using cluster.overplot",col=as.numeric(breast\$ER),xaxt="n",xlim=c(-0.5,1.5)) > axis(1,at=c(0,1),labels=c("Censored","Metastasis")) > count.overplot(jitter(breast\$event_survival), jitter(breast\$time_survival), main="Using cout.overplot",col=as.numeric(breast\$ER),xaxt="n") > axis(1,at=c(0,1),labels=c("Censored","Metastasis")) > sizeplot(breast\$event_survival, breast\$time_survival, main="Using sizeplot",col=as.numeric(breast\$ER),xaxt="n",xlim=c(-0.5,1.5)) > axis(1,at=c(0,1),labels=c("Censored","Metastasis")) > beeswarm(time_survival ~ event_survival, data = breast, + method = 'swarm', + pch = 16, pwcol = as.numeric(ER), + xlab = '', ylab = 'Follow-up time (months)', + labels = c('Censored', 'Metastasis')) > dev.off() quartz 2 > par(opar)```

```> plot(jitter(breast\$event_survival), breast\$time_survival, main="Using Jitter on x-axis",col=as.numeric(breast\$ER),xaxt="n",xlim=c(-0.5,1.5)) > axis(1,at=c(0,1),labels=c("Censored","Metastasis")) > plot(jitter(breast\$event_survival), jitter(breast\$time_survival), main="Using Jitter on x and y-axis",col=as.numeric(breast\$ER),xaxt="n",xlim=c(-0.5,1.5)) > axis(1,at=c(0,1),labels=c("Censored","Metastasis"))```

```> plot(rep(c(1,5,10),each=5), c(jitter(rep(100,5),factor=1), jitter(rep(100,5),factor=5), jitter(rep(100,5), factor=10)), col=c("red","blue","green","gray","black"), xlim=c(-2,13), xlab="", ylab="y", xaxt="n", main="jitter(rep(100,5)) with different factor") > axis(1,at=c(1,5,10),labels=c(paste("factor=",c(1,5,10),sep="")))```

```> require(beeswarm) > data(breast) > library(ggplot2) > p<-ggplot(breast, aes(event_survival,time_survival)) > print(p+geom_jitter(aes(color=ER))+scale_colour_manual(value = c("black", "red")) + scale_x_continuous(breaks = c(0:1), labels = c("Censored", "Metastasis")))```

ggplot点柱图

```> data(iris);library(plotrix) > ehplot(iris\$Sepal.Length, iris\$Species, + intervals=20, cex=1.8, pch=20, main="pch=20") > ehplot(iris\$Sepal.Width, iris\$Species, + intervals=20, box=TRUE, median=FALSE, main="box=TRUE") > ehplot(iris\$Petal.Length, iris\$Species, + pch=17, col="red", log=TRUE, main="pch=17") > ehplot(iris\$Petal.Length, iris\$Species, + offset=0.06, pch=as.numeric(iris\$Species), main="pch=as.numeric(iris\$Species)") > rnd <- sample(150) > plen <- iris\$Petal.Length[rnd] > pwid <- abs(rnorm(150, 1.2)) > spec <- iris\$Species[rnd] > ehplot(plen, spec, pch=19, cex=pwid, + col=rainbow(3, alpha=0.6)[as.numeric(spec)], main="cex and col changes")```