Suppose I have two data frames
df1 = data.frame(x=1:10)
df2 = data.frame(x=11:20)
and I need a scatter plot with these two rows defining the coordinates. It would be simple to do
plot(df1$x,df2$x)
From what I can say so far about ggplot2, I could also do
df = data.frame(x1 = df1$x, x2 = df2$x)
ggplot(data = df, aes(x=x1, y=x2)) + geom_point()
rm(df)
but it will be slower (for me) than creating a new data frame, it is difficult to read and can lead to an increase in errors (deleting an incorrect data frame, writing to the desired data frame, forgetting to remove excess clutter, etc.). Do I really need to create a separate data frame to accommodate the data that is already there? Why does the first line of work work, even if it displays only one of the data frames under "data", and the second line does not work?
ggplot(data = df1, aes(x=df1$x, y=df2$x)) + geom_point()
ggplot( aes(x=df1$x, y=df2$x)) + geom_point()
Here is an example image of basically what I want:

randy source
share