Multiple scatterplots in one graph

Incredibly, I have not been able to find an answer to this question on the web (there are multiple articles and pages but nothing that fits my case, apparently).

I have a graph of the form
ggplot(dataset, aes(x =, y = , label=))+
geom_point(alpha =, color=)+
labs(title=, x = , y = )+
theme_minimal()+
geom_text(size=, hjust=, vjust=)+
xlim()+ylim()
and I would like to merge it with another graph of the same form but with a y referencing a different column in the same dataset.

Will this work?

library(ggplot2)
df1 <- data.frame(x=c(1,2,3,4,5), y=c(1,2,3,4,5))
df2 <- data.frame(x=c(5,6,7,8,9,10), y=c(10,9,8,7,6,5))
ggplot() +
geom_point(data = df1, aes(x = x, y = y), color = "red") +
geom_point(data = df2, aes(x = x, y = y), color = "blue") +
xlab('xlabel') +
ylab('ylabel')

1 Like

The second graph needs to be a column in the same dataset. I will try using the template with the same "data=" though.

Can you share part of both df using dput(head(yourdf, 10))
An option can be a join and than pivot longer

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.