我想在我的数据中添加一行:
我的部分数据:
dput(d[1:20,])
structure(list(MW = c(10.8, 10.9, 11, 11.7, 12.8, 16.6, 16.9,
17.1, 17.4, 17.6, 18.5, 19.1, 19.2, 19.7, 19.9, 20.1, 22.4, 22.7,
23.4, 24), Fold = c(21.6, 21.8, 22, 23.4, 25.6, 33.2, 33.8, 34.2,
34.8, 35.2, 37, 38.2, 38.4, 39.4, 39.8, 40.2, 44.8, 45.4, 46.8,
48), Column = c(33.95, 33.95, 33.95, 33.95, 33.95, 33.95, 33.95,
33.95, 33.95, 33.95, 33.95, 33.95, 33.95, 33.95, 33.95, 33.95,
33.95, 33.95, 33.95, 33.95), Bool = c(1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)), .Names = c("MW", "Fold",
"Column", "Bool"), row.names = c(NA, 20L), class = "data.frame")
Run Code Online (Sandbox Code Playgroud)
行数据:
> dput(bb[1:20,])
structure(c(1.95, 3.2, 3.7, 4.05, 4.5, 4.7, 4.75, 5.05, 5.2,
5.2, 5.2, 5.25, 5.3, 5.35, 5.35, 5.4, 5.4, 5.45, 5.5, 5.5, 10,
33.95, 58.66, 84.42, 110.21, 134.16, 164.69, 199.1, 234.35, 257.19,
361.84, 432.74, 506.34, 581.46, 651.71, 732.59, 817.56, 896.24,
971.77, 1038.91), .Dim = c(20L, 2L), .Dimnames = list(NULL, c("b",
"a")))
Run Code Online (Sandbox Code Playgroud)
最后是我用来创建这个图的代码:
first_dot <- ggplot(d, aes(x=MW, y=Column)) +
geom_point() +
scale_x_continuous(limits=c(0, 650), breaks=c(0, 200, 400, 650)) +
scale_y_continuous(limits=c(0, 1200), breaks=c(0, 400, 800, 1200))
first_dot + geom_line(bb, aes(x=b, y=a))
Run Code Online (Sandbox Code Playgroud)
当我尝试运行它时,我总是收到此错误:
Error: ggplot2 doesn't know how to deal with data of class uneval
你知道我做错了什么吗?
这就是没有线的数据的样子:

以及添加后的样子(大约):

以防万一有人来到这里寻找“如何在现有图的顶部绘制来自不同数据框的线”的[潜在]问题的答案:
这里的关键点是data=在调用中使用geom_line。假设data=我们中的一些人发生了不需要的情况,这通常是它不起作用的原因。正确的代码应该是,正如@Roland 在对问题的评论中所说的那样:
ggplot(d, aes(x=MW, y=Column)) +
geom_point() +
scale_x_continuous(limits=c(0, 650), breaks=c(0, 200, 400, 650)) +
scale_y_continuous(limits=c(0, 1200), breaks=c(0, 400, 800, 1200))+
geom_line(data=as.data.frame(bb),aes(x=b,y=a))
Run Code Online (Sandbox Code Playgroud)