Let\'s say I have a dataframe with one column x and other variables y1, y2, ... all continuos.
What\'s the quickest way to plot x ~ y1 and y2 on two different graphs but
This type of problems generaly has to do with reshaping the data. The format should be the long format and the data is in wide format.
I will use the first 3 columns of built in dataset iris as an example dataset.
library(ggplot2)
df1 <- iris[1:3]
names(df1) <- c("x", "y1", "y2")
df1_long <- reshape2::melt(df1, id.vars = "x")
head(df1_long)
ggplot(df1_long, aes(x, value, colour = variable)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE) +
facet_grid(rows = vars(variable))