The multiple linear regression model is Load=-33.124+1.470VO2max-4.909Gradient I'm working in ggplot2 and tried to draw four different regression line by varying "Gradient=0,5,10 and 15" and also drawing the line segment having at VO2max=50,60 and 75 and finding the intersection point to get the value of the Load.
library("ggplot2")
df<- data.frame(load=rep(c(0,4.4,10.7,17,21.4), each=4),
Gradient=c(0,5,10,15),
VO2max=c(28.0,41.0,56.3,71.3,28.2,41.1,57.0,75.0,31.0,45.4,63.6,82.1,
32.0,48.8,66.8,85.5,34.6,50.5,69.9,89.3))
df$Gradient <- as.factor(df$Gradient)
x5 <- -57.669+7.35
x10 <- -82.214+14.7
x15 <- -106.759+22.05
ggplot(df, aes(vo2max,load, group = Gradient)) +
geom_point(aes(shape = Gradient), size = 3) +
geom_abline(aes(slope = 1.47, intercept = -33.124)) +
geom_abline(aes(slope = 1.47, intercept = -57.669)) +
geom_abline(aes(slope = 1.47, intercept = -82.214)) +
geom_abline(aes(slope = 1.47, intercept = -106.759)) +
geom_segment(data = data.frame(x = c(50, 60, 75),
y = c(x5, x10, x15),
Gradient = factor(c(50, 60, 75))),
aes(x, y, xend = 0, yend = y, colour = Gradient),
linetype = 2) +
geom_point(data = data.frame(VO2max = c(50, 60, 75),
load = c(x5, x10, x15),
Gradient = 1)) +
coord_cartesian(xlim = c(0, 105), ylim = c(0, 25),
expand = 0) +
geom_hline(data = data.frame(x = c(50, 60, 75),
Gradient = factor(c(50, 60, 75))),
aes(yintercept = y, colour = Gradient), linetype = 2) +
theme_minimal() +
theme(axis.line = element_line()) +
guides(colour = "none")
data.frame(x = c(50, 60, 75),y = c(x5, x10, x15))
By running the code I'm getting error as: Don't know how to automatically pick scale for object of type data.frame. Defaulting to continuous. Error: Aesthetics must be either length 1 or the same as the data (20): x
Help me in solving the error and getting perfect graph
