项目要求:
- select 5 figures from “Nature”(从自然杂志中选择5张图表)
- draw the same figure with fake data(用假数据绘制相同的图形)
- submit (1)R code + randata (确保复制过来能直接用)(2)report original figure (把原文出处标注出)
一、韦恩图
#韦恩图
install.packages("VennDiagram")
library(VennDiagram)
getwd()
setwd('E:/大三上/R语言/picture')
getwd()
setwd("E:/大三上/R语言/picture")
venn<-venn.diagram(list(A = 1:150, B =c(121:170,300:320),C=c(20:40,141:200)),
filename=NULL,
col = "black",#表示对应圆周的颜色
fill = c("cornflowerblue", "green", "yellow"),#表示各个集合对应的圆填充颜色
alpha = 0.4,
cat.col = c("darkblue", "darkgreen", "orange"), #表示集合名称的显示颜色
cat.cex = 1.5,
rotation.degree = 0,
lwd=1,#设定圆弧的宽度
lty=1,
main = "韦恩图");#设定圆弧的线型
grid.draw(venn)
二、折线图
#折线图
par(pch=22, col="red") # 设置绘图符号和颜色,下图表示的就是绘图符号
par(mfrow=c(2,2)) # 设置绘图版面,将画布设置成2行4列的格式,共8个绘图区域
data=read.table("E:/大三上/R语言/zhexian.txt",header = T,sep = "\t")
data
plot(data$x0,data$y1,
main="折线图1",#自定义标题
sub="例1",#副标题
xlab="year",ylab="weight",#X、Y轴标题
col="red",
pch=3,#点类型参数
lwd=2,#点边框粗细参数
type='s')
#lines(data$x0,data$y2,pch=2,cex=1.2,lwd=2,col="blue",type='o')
plot(data$x0,data$y2,
main="折线图2",#自定义标题
sub="例2",#副标题
xlab="year",ylab="weight",#X、Y轴标题
col="blue",
pch=3,#点类型参数
lwd=2,#点边框粗细参数
type='s')
plot(data$x0,data$y3,
main="折线图3",#自定义标题
sub="例3",#副标题
xlab="year",ylab="weight",#X、Y轴标题
col="green",
pch=3,#点类型参数
lwd=2,#点边框粗细参数
type='s')
plot(data$x0,data$y4,
main="折线图4",#自定义标题
sub="例4",#副标题
xlab="year",ylab="weight",#X、Y轴标题
col="yellow",
pch=3,#点类型参数
lwd=2,#点边框粗细参数
type='s')
lines(data$x0,data$y3,pch=5,cex=1.2,lwd=2,col="green",type='o')
#lines(data$x0,data$y4,pch=5,cex=1.2,lwd=2,col="yellow",type='o')
legend("topright",
c("y1", "y2","y3","y4"),
pch = c(3,2,5),
col=c("red","blue","green","yellow"),
bg ="white")
三、热图
install.packages("pheatmap")
library(pheatmap)
mtcars#R自带汽车想换数据
data<- as.matrix((scale(mtcars))) #归一化,转换成矩阵
pheatmap(data,
treeheight_row=140,
treeheight_col=11,
cluster_cols=FALSE,#不按列聚类
color=colorRampPalette(c("yellow","white","red"))(1000),
border_color=NA,#方格边框颜色设置
fontsize=10,
fontsize_row=8,
display_numbers=FALSE)#是否填充数字
四、柱状图
#柱状图
library(ggplot2)
now=c(153,165,146,158,163,167,180)
pre=c(130,134,126,154,123,144,145)
value.df<-data.frame(pre,now)
barplot(value.df$now)
barplot(value.df$now,
horiz=T,#水平柱状图
beside = FALSE,
axes = TRUE,
col = "red4",
border="red",
xlab="Numbers of Cells",ylab="value", main="value of item",
names.arg=c(1:7))
values<-as.matrix(value.df)
values<-t(values)
values
barplot(values,
horiz=T,
beside = FALSE,axes = TRUE,
xlab="Numbers of Cells",ylab="value",
names.arg=c(1:7))
五、面积图
library("gcookbook")
uspopage
#ggplot(uspopage,aes(Year,Thousands,fill=AgeGroup))+geom_area()
#ggplot(uspopage,aes(Year,Thousands,fill=AgeGroup))+geom_area(position="stack")
#ggplot(uspopage,aes(Year,Thousands,fill=AgeGroup))+geom_area(position="identity")
ggplot(uspopage,aes(Year,Thousands,fill=AgeGroup))+geom_area(position="stack",alpha=0.7)+facet_wrap(~AgeGroup)