Skip to content
Prev 273365 / 398506 Next

how do i put two scatterplots on same graph

This where it is important to follow the posting (see note immediately above about self-contained examples).  But if you have two data frames, you can plot one and then use the points() function to plot the data from the other on the same graph.  Something like

##create some data
red_flowers <- data.frame(stem.len=sample(7:15,25,replace=TRUE), num.petals=sample(35:55,25,replace=TRUE))
white_flowers <- data.frame(stem.len=sample(5:12,25,replace=TRUE), num.petals=sample(45:85,25,replace=TRUE))

##plot the red flowers
plot(red_flowers$stem.len, red_flowers$num.petals, col='red', xlim=c(5,15), ylim=c(35,85))

##use points() to plot the white flowers
points(white_flowers$stem.len, white_flowers$num.petals)

You will need to make sure you set the x and y axis limits so as not to truncate values in either data frame.


Hope this is helpful,

Dan

Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA 98504-5204