服务热线
178 0020 3020
上传不了照片,这是为什么!!
作业使用R markdown 完成,如有兴趣请看代码压缩文件R2-01(R05).Zip
library("ggplot2")#R1_data <- read.csv(file.choose()) # R markdown 一直报错,不知道为啥?R1_data <- read.csv(file = "/Users/Adobe/Desktop/D/R/phase2/R2-1/data/R2-1-1.csv",header = T)head(R1_data) #查看数据的前几列
## SIZE A B ## 1 S -2.66 2.14 ## 2 M 2.36 1.73 ## 3 M -1.44 2.23 ## 4 M -1.04 1.42 ## 5 M 2.15 1.80 ## 6 M 3.31 1.71
str(R1_data)
## 'data.frame': 95 obs. of 3 variables: ## $ SIZE: Factor w/ 3 levels "L","M","S": 3 2 2 2 2 2 2 1 1 1 ... ## $ A : num -2.66 2.36 -1.44 -1.04 2.15 3.31 -2.46 -1.48 1.57 1.15 ... ## $ B : num 2.14 1.73 2.23 1.42 1.8 1.71 2.12 2.26 1.82 2.47 ...
R1_data <- na.omit(R1_data) #忽略空值
According plot shape choose “Hollow triangle” shape = 2 Adjust xlim $ ylim
p <- ggplot(R1_data,aes(x = A ,y = B ,color = SIZE)) + geom_point(shape = 2) + labs(x = "A gene expression" ,y = "B gene expression", title = "R05-1",caption = "It's really my work ,see my name,hahahahah") + xlim(-2,3) + ylim(-1,3) print(p)
## Warning: Removed 5 rows containing missing values (geom_point).
getwd()
## [1] "/Users/Adobe/Desktop"
ggsave("R2-01-01.png",dpi = 300) # save square png plot
## Saving 7 x 5 in image
## Warning: Removed 5 rows containing missing values (geom_point).
ggsave("R2-01-01.pdf",dpi = 300) # save square pdf plot
## Saving 7 x 5 in image
载入需要的包ggplot2 & 读入数据
library("ggplot2")#R2_data <- read.csv(file.choose()) # R markdown 一直报错,不知道为啥?R2_data <- read.csv(file = "/Users/Adobe/Desktop/D/R/phase2/R2-1/data/R2-1-2.csv",header = T)head(R2_data) #查看数据的前几列
## SIZE Time value ## 1 N 1 2.14 ## 2 N 2 1.73 ## 3 N 3 2.23 ## 4 N 4 1.42 ## 5 L 1 1.80 ## 6 L 2 1.71
使用str函数查看数据框的数据集
str(R2_data)
## 'data.frame': 16 obs. of 3 variables: ## $ SIZE : Factor w/ 4 levels "H","L","M","N": 4 4 4 4 2 2 2 2 3 3 ... ## $ Time : int 1 2 3 4 1 2 3 4 1 2 ... ## $ value: num 2.14 1.73 2.23 1.42 1.8 1.71 2.12 2.26 1.82 2.47 ...
R2_data <- na.omit(R2_data) #忽略空值
start to plot
p <- ggplot(R2_data,aes(x = Time ,y = value ,color = SIZE,shape = SIZE)) + geom_point(size = 3) + geom_line(col = "black")#scale_fill_manual(values = "red","green","blue","NA" ) 先测试一下#shape = c(1,2,0,3)#fill = c("red","green","blue")print(p)
可以使用ggtitle(“this is a title”) 或者 labs(title = “this is a title”)
p <- p + ggtitle("R05-1-2") print(p)
given figure is square
getwd()
## [1] "/Users/Adobe/Desktop"
ggsave("R2-01-02.png",dpi = 300) # save square png plot
## Saving 7 x 5 in image
ggsave("R2-01-02.pdf",dpi = 300) # save square pdf plot
## Saving 7 x 5 in image
附件