I'm attempting to plot selected samples from the larger group of samples I have in a data frame in R.
The data frame is constructed as follows:
round1Counts <- data.frame(
Sample = c(round1[1:20,1], "LowerLimit", "UpperLimit"),
Day = c(rep("1",22), rep("3",22), rep("6",22), rep("8",22)),
Counts = c(strtoi(round1[1:20,2]), 50000, 240000, strtoi(round1[1:20,3]), 50000, 240000, strtoi(round1[1:20,4]), 50000, 240000, strtoi(round1[1:20,5]), 50000, 240000)
)
round1Counts$Sample <- as.character(round1Counts$Sample)
round1Counts$Sample <- factor(round1Counts$Sample, levels=c(round1[,1],"LowerLimit","UpperLimit"))
round1 is a 20 by 5 matrix, where the first column is a list of ids and the following 4 are different time points.
My strategy so far works when including all samples but only selecting certain timepoints,
# All samples, days 1 & 3
ggplot(data = round1Counts[1:44,], aes(x = Day[1:44], y = Counts[1:44], group = Sample[1:44], color = Sample[1:44])) +
geom_line() +
theme(panel.background = element_rect(fill = "white", colour = "grey50"))
but fails when I attempt to isolate certain samples,
# First 5 samples, days 1 & 3
ggplot(data = round1Counts[c(1:5,23:27),], aes(x = Day[c(1:5,23:27)], y = Counts[c(1:5,23:27)], group = Sample[c(1:5,23:27)], color = Sample[c(1:5,23:27)])) +
geom_line() +
theme(panel.background = element_rect(fill = "white", colour = "grey50"))
generating the following error:
geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?
Warning message:
Removed 5 row(s) containing missing values (geom_path).
The function does not seem to recognize that round1Counts[1,] and round1Counts[23,] refer to the same sample, but I would expect grouping by Sample to allow recognition, as the same value is located at both of these indices.