We change the name of column x2
in the df2
to match the name of the corresponding column x1
in df1
. Then we create a unique data frame df
with rbind
. We use melt
from the reshape2
package to convert data to a long format and keep a identifier of the original data frame: df$variable
. Finally we plot the scatterplot using ggplot2
and colours to differentiate between the two data frames.
library(reshape2)
library(ggplot2)
names(df2) <- c("x1", "y2")
df <- rbind(melt(df1, id.vars = "x1"), melt(df2, id.vars = "x1"))
ggplot(df, aes(x1, y = value, colour = variable)) +
geom_point() + labs(x = "x", y = "y") +
scale_colour_manual(values = c("red", "blue"), labels = c("df1", "df2"))

Data
df1 <- structure(list(x1 = c(42.39, 38.77, 44.43, 42.37, 48.79, 46,
53.71, 47.38, 43.75, 46.95), y1 = c(2.1, 2.1, 2.6, 2, 3.6, 2,
2.7, 1.8, 3.1, 3.9)), .Names = c("x1", "y1"), class = "data.frame", row.names = c(NA,
-10L))
df2 <- structure(list(x2 = c(53.05, 43.81, 42.67, 41.74, 42.99), y2 = c(8.4,
2.6, 2.4, 3.4, 2.9)), .Names = c("x2", "y2"), class = "data.frame", row.names = c(NA,
-5L))