Skip to content
Prev 366658 / 398502 Next

Adding regression line to each individual plot in a window with multiple plots

Hi Jake,

You could consider switching to ggplot2

# create a dummy dataset
dataset <- data.frame(
  XA = rnorm(100),
  XB = rnorm(100, mean = 10),
  YA = rnorm(100),
  YB = rnorm(100, mean = -10)
)
# convert it to long format
library(tidyr)
long <- dataset %>%
  gather("Xcat", "Xvalue", XA:XB) %>%
  gather("Ycat", "Yvalue", YA:YB)
# create the plot
library(ggplot2)
ggplot(long, aes(x = Xvalue, y = Yvalue)) +
  geom_smooth(method = "lm") +
  geom_point() +
  facet_grid(Ycat ~ Xcat, scales = "free")

Best regards,

ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and
Forest
team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
Kliniekstraat 25
1070 Anderlecht
Belgium

To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to say
what the experiment died of. ~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data. ~ Roger Brinner
The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey

2017-01-18 2:04 GMT+01:00 Jake William Andrae <jake.andrae at adelaide.edu.au>:

  
  
Message-ID: <CAJuCY5wmgn5XGhU+GCa1Ugv43AD20XLnhdOzXUsO_Snw5uRRhw@mail.gmail.com>
In-Reply-To: <SY3PR01MB20745B1467237858E3F4F186A97F0@SY3PR01MB2074.ausprd01.prod.outlook.com>