Skip to content
Prev 66010 / 398502 Next

how to draw xyplot figure like figure 4.18 of MASS (4th) ?

I am not sure of what you really want.  Do you want one scatterplot with 
'month' in the x axis and 'md' in the y axis, with a line joining each point 
on the plot? Or you want a regression line with a diferent color for each 
group? Or do you want them in 3 separate panels?

If you want one plot and 3 different colors and smoothed lines joining each 
group you can try

d<-read.table('clipboard', header = T) #I copied your data from the 
clipboard
library(lattice)
plot(month,md, col = c('red','blue','black'), type='p')
lines(lowess(d[group=='NN',1]), col = 'red') #overlays a smoothed line to 
your points
lines(lowess(d[group=='SN',1]), col = 'blue')
lines(lowess(d[group=='TP',1]),col = 'black')

Or you can create 3 plots in one graph panel

par(mfrow = c(2, 2)) #2 by 2 plot panel.  Also try par(mfrow = c(3, 1)) and 
see if you like it better
plot(d[group=='NN','month'],d[group=='NN','md'], col = 'red', type='p') 
#plots the 'NN' points
lines(lowess(d[group=='NN',1]), col = 'red') #adds a smoothe line to the 
NN's
plot(d[group=='SN','month'],d[group=='SN','md'], col = 'blue', type='p')
lines(lowess(d[group=='SN',1]), col = 'blue')
plot(d[group=='TP','month'],d[group=='TP','md'], col = 'black', type='p')
lines(lowess(d[group=='TP',1]), col = 'black')

I see that the group 'SN' stays pretty much the same over time, 'TP' shows a 
decreasing trend over time and 'NN' shows that you almost have two separate 
groups with different responses!

Is this what you wanted to do?

Cheers

Francisco