服务热线
178 0020 3020
Assignment 2
getwd() setwd("/Users/Adobe/Desktop/R/A4") #Set up working space getwd()
pdf(file="A4-1_boxplot.pdf")
#pdf函数会生成一个矢量图片,不会因为放大而模糊而且文件很小,推荐大家使用。
#其他函数比如png()等可以设置清晰度,但是文件偏大
#具体请参考链接http://blog.sina.com.cn/s/blog_1393e7b920102x6sk.htm)
#例如如下代码:
png("file="A4-1_boxplot.pdf"",width=600,height=600)
mydata<-read.csv("data1.csv") #input a table mydata boxplot(Height~Body, #以Body 为因子画出Height的 boxplot data = mydata, main="Adult's Body Index", notch=FALSE, #设置box时候有缺口 col=rainbow(3), horizontal= TRUE) #设置box是否水平
#read.csv() 和 read.table()具体区别请看链接
#http://blog.csdn.net/anneqiqi/article/details/51085675
dev.off() #关闭图形设备
Figure
A3
cancer <- read.csv(file.choose()) #file.choose()可以开启一个选项卡,灰常方便 rownames(cancer) <- cancer[,1] cancer <- cancer[,-1] pdf(file = "boxplot.pdf",8,6) #输出pdf,并设置宽度8高度6inches,默认为7
boxplot(KRAS~TUMOR, #以TUMOR为因子,画出KRAS的boxplot data = cancer, #上面变量的来源的数据框frame或者list boxwex = 0.25, #box的宽度,以为有多组,所以宽度窄一些比较好 at = c(2,4)-0.5, #设置每个box的开始画的点,这是从1.5和3.5开始 xlab = "Gene", ylab = "Expression", xlim = c(1.2,4.8), ylim = c(0,2100), #设置,X,Y轴的范围 axes = F, #暂时禁止生成坐标轴,后面进行自定义。 main = "RAS expression", col = "green" )
boxplot(NRAS~TUMOR, data = cancer, add= T, #逻辑值,如果为TRUE,则在现有的图上增加 boxwex = 0.25, #R011同学很聪明呀,以(2,4)为基准值 at = c(2,4), names = c("Normal","Tumor"), #设置每组的box名称 col = "yellow" )
boxplot(HRAS~TUMOR, data = cancer, add= T, boxwex = 0.25, at = c(2,4)+0.5, axes = F, #如果axes=TRUE,每次都会默认生成一个坐标轴 col = "purple" )
legend(1.5,2000, #设置legend图例开始的点 cex= 1.2, #cex设置文字的放大倍数,参考下面链接 bty = "n", #图例填充的边框类型,o表示有边框,n为无边框 c("KRAS","NRAS","HRAS"), fill = c("green","yellow","purple") #图例填充的颜色 )
#legend具体请参考help(legend)或者下面链接
#http://blog.csdn.net/myl1992/article/details/45826931
#高级绘图参数,例如cex等参考如下链接
#http://www.cnblogs.com/holbrook/archive/2013/05/13/3075777.html
dev.off()
附件