[R] how to draw xyplot figure like figure 4.18 of MASS (4th) ?
Francisco J. Zagmutt
gerifalte28 at hotmail.com
Wed Mar 16 21:22:34 CET 2005
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
>From: Zhongming Yang <zhongmingyang at yahoo.com>
>To: "Francisco J. Zagmutt" <gerifalte28 at hotmail.com>,
>r-help at stat.math.ethz.ch
>Subject: RE: [R] how to draw xyplot figure like figure 4.18 of MASS (4th) ?
>Date: Wed, 16 Mar 2005 09:01:07 -0800 (PST)
>
>Dear Francisco and All:
>
>Following is the source code to create figure 4.18 from MASS (4th).
>
>library(MASS)
>library(lattice)
>if(F) { # no data supplied
>xyplot(ratio ~ scant | subject, data = A5,
> xlab = "scan interval (years)",
> ylab = "ventricle/brain volume normalized to 1 at start",
> subscripts = T, ID = A5$ID,
> strip = function(factor, ...)
> strip.default(..., factor.levels = labs, style = 1),
> layout = c(8, 5, 1),
> skip = c(rep(FALSE, 37), rep(TRUE, 1), rep(FALSE, 1)),
> panel = function(x, y, subscripts, ID) {
> panel.xyplot(x, y, type = "b", cex = 0.5)
> which <- unique(ID[subscripts])
> panel.xyplot(c(0, 1.5), pr3[names(pr3) == which],
> type = "l", lty = 3)
> if(which == 303 || which == 341) points(1.4, 1.3)
> })
>}
>
>But there is no data set available for that, I can't figure out many stuff.
>So I provide my data set, hope you can help me.
>
>In my data set, there are 3 group patients, and 5 patients in each group.
>The mds are the repeat measurements on month. I want draw a xyplot with 3
>lines, each line for a group.
>
>
>Many thanks
>
>Zhongming Yang
>
>
>
>
>"Francisco J. Zagmutt" <gerifalte28 at hotmail.com> wrote:
>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
>
> >From: Zhongming Yang
> >To: r-help at stat.math.ethz.ch
> >Subject: [R] how to draw xyplot figure like figure 4.18 of MASS (4th) ?
> >Date: Wed, 16 Mar 2005 08:07:21 -0800 (PST)
> >
> >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
> >
> >
> >
> >---------------------------------
> >
> > md idno month group
> > -0.090 521 0.000000 NN
> > -1.330 521 12.460274 NN
> > -0.570 521 14.991781 NN
> > -2.130 559 0.000000 NN
> > -0.920 559 3.978082 NN
> > -1.730 559 6.016438 NN
> > -2.390 559 9.665753 NN
> > -1.300 559 12.460274 NN
> > -2.170 559 15.682192 NN
> > -2.620 559 17.950685 NN
> > -1.830 559 21.664406 NN
> > -3.090 559 25.533258 NN
> > -2.760 559 30.811947 NN
> > -1.240 559 33.830137 NN
> > -0.650 559 36.394521 NN
> > -1.200 559 38.893151 NN
> > -1.320 559 42.147945 NN
> > -2.000 559 45.600000 NN
> > -2.150 559 48.328767 NN
> > -1.430 559 52.569863 NN
> > -2.650 559 56.120548 NN
> > -0.870 559 60.032877 NN
> > -1.920 559 63.550685 NN
> > -2.320 559 65.786301 NN
> > -2.640 559 68.547945 NN
> > -2.030 559 71.533258 NN
> > -1.900 559 75.500472 NN
> > -1.420 559 78.254570 NN
> > -1.330 559 81.863014 NN
> > -2.120 559 84.657534 NN
> > -2.400 559 86.926027 NN
> > -2.410 559 90.147945 NN
> > -3.370 559 93.369863 NN
> > -0.720 559 96.624658 NN
> > -2.075 598 0.000000 NN
> > -2.260 598 3.484932 NN
> > -2.150 598 5.917808 NN
> > -1.420 598 9.828879 NN
> > -1.490 598 12.353470 NN
> > -3.040 598 16.025601 NN
> > -1.960 598 18.845273 NN
> > -2.780 598 22.224658 NN
> > -3.310 598 24.591781 NN
> > -4.420 598 27.517808 NN
> > -1.890 598 30.312329 NN
> > -3.000 598 33.304110 NN
> > -2.260 598 36.065753 NN
> > -0.730 598 40.010959 NN
> > -2.710 598 43.232877 NN
> > -2.430 598 45.994521 NN
> > -1.050 598 49.183562 NN
> > -2.190 598 52.438356 NN
> > -0.580 598 54.969863 NN
> > -2.050 598 57.501011 NN
> > -1.480 598 60.681338 NN
> > -0.960 598 63.664945 NN
> > -2.090 598 66.419043 NN
> > -3.180 598 69.435616 NN
> > -1.230 598 72.394521 NN
> > -2.170 598 74.761644 NN
> > -2.400 598 78.378082 NN
> > -3.630 598 81.698630 NN
> > -2.100 598 84.920548 NN
> > -3.940 598 87.156164 NN
> > -3.780 598 90.378082 NN
> > -5.690 598 95.967123 NN
> > -13.525 622 0.000000 NN
> > -12.670 622 3.680934 NN
> > -13.500 622 7.123557 NN
> > -13.700 622 9.910442 NN
> > -11.260 622 12.926836 NN
> > -12.100 622 15.846575 NN
> > -13.400 622 18.410959 NN
> > -12.330 622 21.435616 NN
> > -12.940 622 24.197260 NN
> > -12.540 622 27.156164 NN
> > -12.550 622 29.917808 NN
> > -11.900 622 33.830137 NN
> > -11.640 622 36.394521 NN
> > -12.100 622 38.893151 NN
> > -11.010 622 41.457534 NN
> > -12.050 622 46.684932 NN
> > -12.650 622 50.136986 NN
> > -11.620 622 54.303885 NN
> > -12.150 622 58.303885 NN
> > -12.990 622 60.959623 NN
> > -12.590 622 63.912329 NN
> > -13.570 622 66.936986 NN
> > -12.480 622 69.336986 NN
> > -12.800 622 72.263014 NN
> > -12.640 622 75.452055 NN
> > -13.830 622 81.073973 NN
> > -13.250 622 84.295890 NN
> > -13.700 622 90.213699 NN
> > -13.250 622 96.197260 NN
> > -2.190 801 0.000000 NN
> > -1.250 801 2.663014 NN
> > -1.550 801 5.589041 NN
> > -1.570 801 8.575612 NN
> > -0.880 801 11.755940 NN
> > -0.230 801 15.428071 NN
> > -0.770 801 17.985448 NN
> > -1.050 801 20.975342 NN
> > -2.260 801 24.394521 NN
> > -2.760 801 27.715068 NN
> > -1.550 801 29.950685 NN
> > -2.330 801 34.093151 NN
> > -1.390 801 36.394521 NN
> > -2.090 801 39.353425 NN
> > -3.050 801 41.917808 NN
> > -1.930 801 44.646575 NN
> > -4.040 801 48.328767 NN
> > -3.260 801 51.780822 NN
> > -2.810 801 54.115068 NN
> > -0.660 801 57.395284 NN
> > -1.800 801 62.903481 NN
> > -1.540 801 65.755940 NN
> > -0.880 801 69.567123 NN
> > -2.000 801 73.117808 NN
> > -1.610 801 76.142466 NN
> > -4.360 801 79.463014 NN
> > -3.200 801 80.712329 NN
> > -3.080 801 83.013699 NN
> > -2.350 801 88.306849 NN
> > -3.170 801 89.917808 NN
> > -3.570 801 95.342466 NN
> > -3.300 525 0.000000 TP
> > -2.500 525 2.991781 TP
> > -5.480 525 5.917808 TP
> > -1.140 525 8.712329 TP
> > -2.260 525 11.967123 TP
> > -0.670 525 14.926027 TP
> > -0.630 525 17.950685 TP
> > -0.600 525 21.336986 TP
> > -1.870 525 24.427397 TP
> > -1.790 525 26.860274 TP
> > -3.640 525 30.771345 TP
> > -2.860 525 33.328722 TP
> > -2.140 525 37.197575 TP
> > -1.560 525 39.787739 TP
> > -0.360 525 42.542466 TP
> > -1.900 525 45.304110 TP
> > -1.190 525 48.032877 TP
> > -3.090 525 51.024658 TP
> > -2.620 525 53.786301 TP
> > -1.360 525 58.126027 TP
> > -1.130 525 60.953425 TP
> > -1.390 525 64.142466 TP
> > -0.270 525 66.904110 TP
> > -1.640 525 69.665753 TP
> > -1.390 525 72.887671 TP
> > -2.550 525 75.221918 TP
> > -2.540 525 78.180822 TP
> > -1.640 525 81.623804 TP
> > -2.410 525 84.574624 TP
> > -2.530 525 88.017247 TP
> > -1.980 525 91.463014 TP
> > -3.060 525 93.895890 TP
> > -1.920 525 96.131507 TP
> > -1.650 525 99.320548 TP
> > -2.625 527 0.000000 TP
> > -2.370 527 2.991781 TP
> > 0.050 527 6.180822 TP
> > -0.270 527 9.041096 TP
> > 1.060 527 11.736986 TP
> > -3.030 527 15.221918 TP
> > -1.000 527 18.180822 TP
> > -1.270 527 21.895890 TP
> > -1.910 527 24.361644 TP
> > -2.350 527 27.649315 TP
> > -3.720 527 30.142825 TP
> > -3.310 527 33.355940 TP
> > -2.280 527 35.847743 TP
> > -1.860 527 39.290366 TP
> > -5.050 527 42.345205 TP
> > -3.160 527 45.106849 TP
> > -2.270 527 47.802740 TP
> > -1.850 527 50.630137 TP
> > -4.010 527 53.621918 TP
> > -4.520 527 56.383562 TP
> > -3.820 527 60.000000 TP
> > -6.440 527 65.293151 TP
> > -4.600 527 68.350685 TP
> > -5.280 527 71.802740 TP
> > -3.920 527 75.320548 TP
> > -5.080 527 78.175612 TP
> > -8.550 527 80.831350 TP
> > -4.900 527 84.601841 TP
> > -11.620 527 87.585448 TP
> > -6.090 527 91.956164 TP
> > -7.120 527 95.408219 TP
> > -6.365 570 0.000000 TP
> > -6.100 570 2.761644 TP
> > -4.950 570 5.983562 TP
> > -5.530 570 9.205479 TP
> > -3.640 570 11.967123 TP
> > -3.330 570 15.879452 TP
> > -4.950 570 18.310442 TP
> > -5.250 570 21.392410 TP
> > -5.540 570 24.376016 TP
> > -4.300 570 27.359623 TP
> > -4.530 570 29.884932 TP
> > -5.970 570 32.646575 TP
> > -4.950 570 37.019178 TP
> > -5.090 570 39.320548 TP
> > -4.000 570 42.312329 TP
> > -6.160 570 45.073973 TP
> > -6.490 570 49.216438 TP
> > -4.890 570 52.668493 TP
> > -6.620 570 56.350685 TP
> > -7.010 570 61.183562 TP
> > -7.290 570 63.978082 TP
> > -6.440 570 66.736672 TP
> > -7.950 570 69.917000 TP
> > -7.570 570 73.130115 TP
> > -8.150 570 76.113721 TP
> > -8.090 570 78.805479 TP
> > -9.670 570 82.553425 TP
> > -9.480 570 86.169863 TP
> > -9.120 570 90.147945 TP
> > -11.330 570 97.019178 TP
> > -3.750 615 0.000000 TP
> > -3.510 615 3.287671 TP
> > -4.160 615 5.848641 TP
> > -5.170 615 9.651920 TP
> > -4.600 615 12.438805 TP
> > -5.940 615 15.619133 TP
> > -6.270 615 18.608219 TP
> > -4.690 615 21.632877 TP
> > -7.820 615 24.361644 TP
> > -5.940 615 27.189041 TP
> > -5.680 615 30.180822 TP
> > -6.750 615 32.712329 TP
> > -5.130 615 36.854795 TP
> > -6.630 615 39.386301 TP
> > -7.450 615 41.917808 TP
> > -7.290 615 45.369863 TP
> > -9.590 615 48.361644 TP
> > -9.700 615 51.353425 TP
> > -9.570 615 54.799461 TP
> > -9.840 615 57.783068 TP
> > -9.800 615 60.766674 TP
> > -11.000 615 63.291264 TP
> > -11.360 615 66.805479 TP
> > -10.860 615 69.731507 TP
> > -10.610 615 72.493151 TP
> > -12.180 615 78.706849 TP
> > -12.570 615 84.690411 TP
> > -13.280 615 90.213699 TP
> > -15.720 615 96.197260 TP
> > 0.375 818 0.000000 TP
> > 1.640 818 2.491803 TP
> > -5.190 818 5.967213 TP
> > -3.080 818 9.674018 TP
> > -4.020 818 12.402785 TP
> > -6.380 818 15.854839 TP
> > -4.570 818 17.926072 TP
> > -5.380 818 21.608264 TP
> > -7.210 818 25.060319 TP
> > -8.560 818 27.854839 TP
> > -7.300 818 30.156209 TP
> > -7.590 818 33.312374 TP
> > -7.050 818 36.600045 TP
> > -7.350 818 38.046620 TP
> > -9.040 818 41.893196 TP
> > -8.340 818 45.573770 TP
> > -6.890 818 48.131148 TP
> > -7.190 818 54.098361 TP
> > -7.690 818 57.312374 TP
> > -9.340 818 60.468538 TP
> > -9.580 818 62.572648 TP
> > -10.180 818 65.827442 TP
> > -9.000 818 69.443881 TP
> > -10.760 818 71.547990 TP
> > -10.580 818 74.112374 TP
> > -10.500 818 78.221963 TP
> > -10.460 818 83.252100 TP
> > -9.980 818 89.071278 TP
> > -4.540 535 0.000000 SN
> > -6.050 535 3.221918 SN
> > -4.040 535 5.983562 SN
> > -2.940 535 8.843836 SN
> > -4.360 535 12.197260 SN
> > -3.760 535 14.958904 SN
> > -2.780 535 18.641096 SN
> > -6.140 535 21.402740 SN
> > -6.070 535 24.164384 SN
> > -6.530 535 27.450528 SN
> > -7.320 535 31.057085 SN
> > -6.270 535 33.778397 SN
> > -6.480 535 36.991511 SN
> > -7.440 535 39.747945 SN
> > -9.400 535 42.509589 SN
> > -6.640 535 45.534247 SN
> > -6.170 535 48.098630 SN
> > -5.090 535 51.090411 SN
> > -4.660 535 53.786301 SN
> > -5.420 535 58.158904 SN
> > -8.420 535 60.920548 SN
> > -4.830 535 63.682192 SN
> > -5.210 535 66.673973 SN
> > -5.030 535 69.961644 SN
> > -4.720 535 72.460274 SN
> > -5.570 535 75.253806 SN
> > -4.240 535 79.122659 SN
> > -5.620 535 82.302987 SN
> > -5.180 535 85.286593 SN
> > -4.560 535 88.076712 SN
> > -3.730 535 91.265753 SN
> > -4.490 535 95.473973 SN
> > -5.010 535 99.221918 SN
> > -3.645 541 0.000000 SN
> > -2.130 541 3.024658 SN
> > -2.240 541 6.016438 SN
> > -4.490 541 9.073973 SN
> > -3.310 541 12.000000 SN
> > -3.320 541 16.339726 SN
> > -4.130 541 18.246575 SN
> > -3.640 541 21.271233 SN
> > -3.510 541 24.624658 SN
> > -5.260 541 27.612666 SN
> > -3.340 541 30.825780 SN
> > -3.990 541 33.678239 SN
> > -5.390 541 37.022502 SN
> > -9.960 541 39.616438 SN
> > -3.740 541 43.002740 SN
> > -4.550 541 45.600000 SN
> > -3.370 541 48.295890 SN
> > -4.810 541 50.893151 SN
> > -3.130 541 53.654795 SN
> > -3.770 541 57.632877 SN
> > -3.820 541 60.558904 SN
> > -5.160 541 63.090411 SN
> > -3.530 541 66.016438 SN
> > -4.690 567 0.000000 SN
> > -4.030 567 2.991781 SN
> > -2.080 567 6.049315 SN
> > -2.430 567 9.698630 SN
> > -3.500 567 12.723288 SN
> > -2.690 567 15.189041 SN
> > -3.260 567 18.476712 SN
> > -4.890 567 21.460768 SN
> > -3.940 567 24.673883 SN
> > -4.150 567 28.313227 SN
> > -2.570 567 31.068493 SN
> > -3.290 567 33.402740 SN
> > -2.650 567 36.394521 SN
> > -1.220 567 39.353425 SN
> > -2.230 567 45.764384 SN
> > -2.780 567 48.526027 SN
> > -3.230 567 51.780822 SN
> > -3.470 567 54.542466 SN
> > -2.440 567 57.041096 SN
> > -4.170 567 61.249315 SN
> > -3.440 567 63.715068 SN
> > -1.880 567 66.279452 SN
> > -2.150 567 69.231260 SN
> > -2.150 567 72.673883 SN
> > -7.010 567 89.720548 SN
> > -4.640 567 94.520548 SN
> > -5.600 567 96.723288 SN
> > -2.375 572 0.000000 SN
> > -2.920 572 3.452055 SN
> > -1.310 572 6.246575 SN
> > -1.890 572 10.158904 SN
> > -2.450 572 12.558904 SN
> > -2.590 572 15.189041 SN
> > -2.040 572 18.308826 SN
> > -1.570 572 21.685875 SN
> > -1.930 572 24.472760 SN
> > -1.300 572 27.817022 SN
> > -2.820 572 30.641096 SN
> > -1.240 572 33.600000 SN
> > -0.720 572 36.394521 SN
> > -0.440 572 39.156164 SN
> > -0.750 572 41.917808 SN
> > -1.310 572 45.567123 SN
> > -1.060 572 48.756164 SN
> > -0.670 572 51.517808 SN
> > -1.110 572 54.279452 SN
> > -0.870 572 57.501370 SN
> > -2.400 572 60.493151 SN
> > -1.790 572 63.484932 SN
> > -1.150 572 66.308826 SN
> > -0.550 572 68.800629 SN
> > -1.830 572 72.112104 SN
> > -1.830 572 75.030137 SN
> > -1.640 572 78.772603 SN
> > -2.340 572 81.468493 SN
> > -2.490 572 86.136986 SN
> > -1.840 572 90.147945 SN
> > -1.760 572 93.369863 SN
> > -0.970 572 96.657534 SN
> > -0.960 583 0.000000 SN
> > -1.150 583 3.189041 SN
> > -2.060 583 7.364384 SN
> > -1.710 583 9.402740 SN
> > -0.870 583 12.427397 SN
> > -2.100 583 15.185179 SN
> > -1.290 583 18.660588 SN
> > -1.350 583 21.185179 SN
> > -0.410 583 24.824523 SN
> > -2.750 583 27.550685 SN
> > -1.860 583 30.345205 SN
> > -1.750 583 33.336986 SN
> > 0.360 583 36.098630 SN
> > -1.200 583 38.893151 SN
> > -0.900 583 42.575342 SN
> > -1.350 583 45.501370 SN
> > -0.660 583 48.526027 SN
> > -0.950 583 51.254795 SN
> > -1.690 583 54.279452 SN
> > -0.410 583 57.073973 SN
> > -1.090 583 60.295890 SN
> > -0.590 583 63.021244 SN
> > -0.800 583 66.004851 SN
> > -0.700 583 69.250752 SN
> > -0.990 583 72.627801 SN
> > -0.240 583 75.879452 SN
> > -0.180 583 78.673973 SN
> > -1.000 583 81.402740 SN
> > -1.360 583 84.164384 SN
> > -1.240 583 86.958904 SN
> > -1.500 583 90.246575 SN
> > -1.410 583 93.468493 SN
> > -4.260 583 96.230137 SN
> >______________________________________________
> >R-help at stat.math.ethz.ch mailing list
> >https://stat.ethz.ch/mailman/listinfo/r-help
> >PLEASE do read the posting guide!
> >http://www.R-project.org/posting-guide.html
>
>
>
>
>
>---------------------------------
More information about the R-help
mailing list