我有一个看似简单的问题,但我一直无法解决。我只想在 ggplot 中绘制 data.frame 的一个子集,但我不断收到错误消息。这是我的有效代码(使用完整的数据集):
ggplot(a2.25, aes(x=V1, y=V2)) + geom_point() +
theme(plot.margin = unit(c(0,0,0,0), "lines"),
plot.background = element_blank(),
axis.title.y = element_blank(),
axis.title.x = element_blank()) +
ggtitle("a2_25")
但是当我尝试仅通过以下方式绘制数据的子集时:
ggplot(a2.25, aes(x=V1[2:24], y=V2[2:24])) + geom_point() +
theme(plot.margin = unit(c(0,0,0,0), "lines"),
plot.background = element_blank(),
axis.title.y = element_blank(),
axis.title.x = element_blank()) +
ggtitle("a2_25")
我收到以下错误消息:“data.frame 中的错误(x = c(0.04, 0.08, 0.12, 0.16, 0.2, 0.24, 0.28, 0.32, : arguments imply different number of rows: 23, 26" 但是,文件由 26 个变量组成。当我分别检查每列的长度时,每列有 26 个观察值。
有谁知道是什么导致了这个错误/克服它的简单方法?我正在对我的数据进行探索性分析,并且有大量文件,并且将在完整数据集和它的子集之间来回转换,因此手动缩短文件将非常乏味。
谢谢!
这是样本数据(dput):
structure(list(V1 = c(0, 0.04, 0.08, 0.12, 0.16, 0.2, 0.24, 0.28,
0.32, 0.36, 0.4, 0.44, 0.48, 0.52, 0.56, 0.6, 0.64, 0.68, 0.72,
0.76, 0.8, 0.84, 0.88, 0.92, 0.96, 1), V2 = c(0.9999396, 1.828642e-05,
2.125182e-05, 1.369786e-05, 6.395666e-06, 7.471323e-07, 9.306843e-09,
1.025577e-11, 1.225776e-15, 2.306844e-20, 1.021365e-25, 1.41806e-31,
6.450008e-38, 7.751817e-45, 1.698149e-52, 4.40356e-61, 8.356799e-71,
6.445585e-82, 9.108883e-95, 7.374944e-110, 5.603281e-128, 1.908444e-150,
9.635286e-180, 1.938155e-221, 2.781784e-293, 0)), .Names = c("V1",
"V2"), class = "data.frame", row.names = c(NA, -26L))