Skip to content

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

7 messages · Uwe Ligges, Zhongming Yang, Francisco J. Zagmutt +1 more

#
Dear All:
 
Could you please tell me how I can draw figure formatted like figure 4.18 of MASS (4th) with the attached data set?
 
Thanks
 
Zhongming Yang


		
---------------------------------

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: sample.txt
Url: https://stat.ethz.ch/pipermail/r-help/attachments/20050316/abfdb85e/sample.txt
#
Zhongming Yang wrote:

            
The example is given on page 101.

Uwe Ligges
#
Dear Zhongming,

By asking for the figure in the book you are restricting you question to 
only the people that has the 4th edition.  I would love to help you but 
unfortunatelly I have the 3rd edition of MASS and there is no figure 4.18 
since chapter 4 is "Programming in S".  Please give us an idea of what you 
want to do and we might be able to help you without looking at the book.

Cheers

Francisco
#
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
#
Ups, one mistake!  Change the second line of the code from library(lattice) 
to attach(d), so you get:

d<-read.table('clipboard', header = T)
attach(d)
plot(month,md, col = c('red','blue','black'), type='p')
lines(lowess(d[group=='NN',1]), col = 'red')
lines(lowess(d[group=='SN',1]), col = 'blue')
lines(lowess(d[group=='TP',1]),col = 'black')

par(mfrow = c(2, 2))
plot(d[group=='NN','month'],d[group=='NN','md'], col = 'red', type='p')
lines(lowess(d[group=='NN',1]), col = 'red')
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')

Francisco
#
I think you have restated your question a couple of days ago here
http://tolstoy.newcastle.edu.au/R/help/05/03/14095.html
I will reply to that thread as it is simpler and easier.

The only new thing this thread adds is "where is the data a5 used to
create Figure 4.18 in MASS (4th Ed)" ?

Regards, Adai
On Wed, 2005-03-16 at 09:01 -0800, Zhongming Yang wrote: