Here's what my data looks like. Long story short, I want to scatterplot Y values from Group A vs respective X values from Group B and optionally color it by Sample.
I do a lot of plotting of data like this (with many more variables), but it's always within a subset like subset(data, Group=='A') or subset(data, Group=='B'). This is the rare case when I need to plot across groups.
The plot code itself is simple:
ggplot(data, aes(x=X(B), y=Y(A), color=as.factor(Sample))) +
geom_point()
I realize that my X(B) and Y(A) won't work; that's just to illustrate the objective. I also assume there's a way to spit out a new dataset containing only the X(B) and Y(A) values; certainly open to any approach, but I prefer to work in GGPLOT for the actual graphs. Here's my dataset for reproducibility:
data <- structure(list(Group = c("A", "A", "A", "A", "A", "B", "B", "B",
"B", "B", "A", "A", "A", "A", "A", "B", "B", "B", "B", "B"),
Sample = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), Point = c(1L, 2L, 3L, 4L,
5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L,
5L), X = c(-3.26, -3.26, -3.26, -3.26, -3.26, -2.3624, -2.3877,
-2.6475, -3.0975, -3.1393, -3.26, -3.26, -3.26, -3.26, -3.26,
-0.6476, -0.7056, -0.7367, -0.9883, -0.9003), Y = c(22.55,
22.02, 19.41, 10.92, 8.3, 4.14, 4.42, 9.92, 9.86, 7.57, 67.94,
66.92, 70.26, 63.37, 61.85, 11.79, 10.86, 12.96, 12.44, 11.69
)), class = "data.frame", row.names = c(NA, -20L))


