有人可以尝试调试下面的脚本吗? ggplot似乎找不到我的x和y值。有什么问题?
数据:
data <- read.table(file="./MatureMiRNA_1M_2M_Trim18.csv", sep=",", header=T, check.names=F, row.names=1)
head(data)
1M 2M
hsa-let-7a-2-3p 0 0
hsa-let-7a-3p 0 12
hsa-let-7a-5p 2770 1344
hsa-let-7b-3p 26 27
hsa-let-7b-5p 627 492
hsa-let-7c-3p 0 0
脚本
keep <- rowSums(cpm(data)>3) >=2
data <- data[keep, ]
table(keep)
keep
FALSE TRUE
2381 200
data <- log(data,2)
head(data)
1M 2M
hsa-let-7a-5p 11.435670 10.392317
hsa-let-7b-3p 4.700440 4.754888
hsa-let-7b-5p 9.292322 8.942515
hsa-let-7c-5p 5.906891 4.754888
hsa-let-7d-3p 9.552669 7.882643
hsa-let-7d-5p 8.573647 7.851749
library(ggplot2)
ggplot(data, aes(x=1M,y=2M)) + geom_point()
Error: unexpected symbol in "ggplot(data, aes(x=1M"
答案 0 :(得分:1)
R不允许以数字(See, for example, here)开头的变量名称。但是check_names=F
命令中的read.table
会阻止R检查有效名称。保留check.names
作为默认值(TRUE),R将通过添加&#34; X&#34;来使名称合法。到变量名。如果要将原始名称作为ggplot中的轴标签,请使用labs
更改轴标签。
data <- read.table(text = " 1M 2M
hsa-let-7a-5p 11.435670 10.392317
hsa-let-7b-3p 4.700440 4.754888
hsa-let-7b-5p 9.292322 8.942515
hsa-let-7c-5p 5.906891 4.754888
hsa-let-7d-3p 9.552669 7.882643
hsa-let-7d-5p 8.573647 7.851749",
header = TRUE,
check.names = TRUE,
row.names = 1)
names(data)
library(ggplot2)
ggplot(data, aes(X1M, X2M)) +
geom_point() +
labs(x = "1M", y = "2M")