I have a seemingly simple question that nonetheless I have not been able to solve. I would like to plot only a subset of a data.frame in ggplot and I keep getting an error. Here is my code that works (with the full data set):
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")
But when I try to only plot a subset of the data via:
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")
I get the following error message: "Error in data.frame(x = c(0.04, 0.08, 0.12, 0.16, 0.2, 0.24, 0.28, 0.32, : arguments imply differing number of rows: 23, 26" However, the file is composed of 26 obs. of 2 variables. When I examine the length of each column separately there are 26 observations in each.
Does anyone know what is causing this error/a simple way to overcome it? I am doing exploratory analysis on my data and have numerous files and will be converting back and forth between the full data set and subsets of it, so it would be very tedious to manually shorten the files.
Thank you!
Here is the samples data (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))
.dataargument rather than theaes:ggplot(a2.25[2:24,], ...