Is there a way to plot 3 separate multiple regressions in the same plot?

50 Views Asked by At
belonging safety wellbeing negpol pospol
3.5 3.2 4.22 1.17 1.32
5.19 3.5 6.06 1.11 1.34
5.00 5.00 5.57 1.06 1.35

These are all scale vriables and some are subscales of larger measures.

negpol: 6 item measure on a scale of 1-4 pospol: 6 item measure on a scale of 1-4 safety: 10 item measure on a scale of 1-5 wellbeing: 16 item measure on a scale of 1-7 belonging: 16 item measure on a scale of 1-5

This my SPSS and R syntax for 3 regressions. I'm trying to plot them in one plot. Is there a way?

fit1 <- lm(safety~negpol+pospol, data=data1)
fit2 <- lm(belonging~negpol+pospol, data=data1)
fit3 <- lm(wellbeing~negpol+pospol, data=data1)`

I'm not sure how I could do this!

1

There are 1 best solutions below

6
jpsmith On

You can do this easily in base R with abline. Using the R-provided mtcars dataset:

m1 <- lm(mpg ~ disp , data = mtcars)
m2 <- lm(mpg ~ disp + hp, data = mtcars)
m3 <- lm(mpg ~ disp + hp + carb, data = mtcars)

plot(x = mtcars$disp, 
     y = mtcars$mpg)
abline(m1)
abline(m2, lty = 2, col = "purple")
abline(m3, lty = 3, col = "red")

enter image description here


The above compares apples to apples. In your question, you are comparing apples to oranges. If you want to look at the effect of negpol while controlling for pospol on three different variables with different scales (however that are somewhat similar (1 to 5 and 1 to 7), you could try something like:

set.seed(123)
n <- 25
data1 <- data.frame(belonging = runif(n, 1, 5),
                    safety = runif(n, 1, 5),
                    wellbeing = runif(n, 1,7),
                    negpol =  runif(n, 1, 4),
                    pospol = runif(n, 1, 4))

fit1 <- lm(safety ~ negpol + pospol, data = data1)
fit2 <- lm(belonging ~ negpol + pospol, data = data1)
fit3 <- lm(wellbeing ~ negpol + pospol, data = data1)

plot(NA, xlim = c(1, 4),
     ylim = c(1, 7),
     axes = FALSE,
     xlab = "Negpol", 
     ylab = "Value")
axis(1, at = 1:4)
axis(2, las = 2)
axis(4, at = 1:5, las = 2)
points(x = data1$negpol,
       y = data1$safety, pch = 21, bg = "maroon")
points(x = data1$negpol,
       y = data1$belonging, pch = 21, bg = "slateblue")
points(x = data1$negpol,
       y = data1$wellbeing, pch = 21, bg = "yellow2")
abline(fit1, col = "maroon", lwd = 2)
abline(fit2, col = "slateblue", lwd = 2)
abline(fit3, col = "yellow2", lwd = 2)

Which would give you something like:

enter image description here

though that may not be the best approach and you may want to reconsider exactly what comparisons you are seeking.