I am using ggplot2 in R to create scatterplots. I have (x,y) datasets for two different conditions as follows:
x1 y1 x2 y2
1 1.00000000 150.36247 0.50000000 133.27397
2 1.00000000 129.62707 0.50000000 120.79893
3 1.00000000 79.94730 0.62500000 78.98120
4 1.00000000 79.78723 0.62500000 81.93014
5 1.00000000 133.47697 0.72727273 192.86557
I would like to plot (x1,y1) and (x2, y2) on the same plot, and draw a trajectory line connecting the two points, for each row in the dataset. For example, in the sample data above, there would be a line connecting (1,150) to (0.5, 133) (the data from row 1) and a separate line connecting (1,129) and (0.5, 120) (the data from row 2) and so on. Ideally, I would also like to make each line a different color.
I tried following the instructions below to create the trajectories but the grouping in my dataset is by columns rather than by rows: Scatterplot with developmental trajectories, and Making a trajectory plot using R
Currently, my script just generates two scatterplots on the same graph but there is no connection between data points of the same row:
scatter2<-ggplot(data = df, aes(x=x1, y=y1))
+ geom_point(aes(x=x1, y=y1), color="red")
+ geom_point(aes(x=x2, y=y2), color="blue")
Any help you can provide would be greatly appreciated! Thank you!
