First, here's the context. I have data from multiple samples that were all analysed with 3 intruments for the same measurements. One of the instrument is the reference one and we want to plot (and analyse) the measurements from the other instruments relative to this reference.
The dataframe looks like this:
| Sample | Instrument | M1 | M2 | M3 |...
| -------| -------- |--- |--- |--- |
| 1 | Ref |
| 2 | Ref |
.
.
| 1 | Test1 |
| 2 | Test2 |
.
.
In which M1, M2, M3 (and so on) are the different measurements.
So, is there an easy way in R to make a plot where X would be the values of a variable Mx from the Ref group and Y the Mx value from one of the other group ?
The group_by function is fine to get statistics but doesn't seem very useful for plots (although it really could be me not knowing how to use it).
Everything I find for dot plots (geom_points) with a linear regression line (lm) ask for X and Y to be in different columns. Although pivot_wide can be used to get these multiple columns (M1_Ref, M2_Ref, M1_Test1..), the resulting dataframe is an ugly mess creating its own problems (mostly that the variables are now ungrouped)... Thus I'm wondering if there's some more elegant way to achieve this.
Something like:
ggplot(df, aes(X, Y, color="Instrument")) + geom_point() + geom_smooth(method = "lm")
The idea being to get a X,Y dot plot with a regression line (and points) for the tested intruments by function of the reference instrument for a specified measurement.
Thanks for any help!