[R] Loop for multiple plots in figure

Marcel Curlin cemarcel at u.washington.edu
Tue Jun 26 08:45:45 CEST 2012


This solution works really nicely & I learned much by working through it.
However but I am having trouble with subplot formatting; setting
main=d$Subject results in the correct title over each plot but repeated
multiple times. Also I can't seem to format the axis labels and numbers to
reduce the space between them and the plot. Any more thoughts appreciated. 

revised code:

tC <- textConnection("
Subject	Xvar	Yvar	param1	param2
bob	9	100	1	100
bob	0	110	1	200
steve	2	250	1	50
bob	-5	175	0	35
dave	22	260	0	343
bob	3	180	0	74
steve	1	290	1	365
kevin	5	380	1	546
bob	8	185	0	76
dave	2	233	0	343
steve	-10	230	0	556
dave	-10	233	1	400
steve	-7	250	1	388
dave	3	568	0	555
kevin	10	380	0	57
kevin	4	390	0	50
bob	6	115	1	600
")
data <- read.table(header=TRUE, tC)
close.connection(tC)
rm(tC)

plot_one <- function(d){
 with(d, plot(Xvar, Yvar, t="n", tck=0.02, main=d$Subject, xlim=c(-14,14),
ylim=c(0,600))) # set limits
 with(d[d$param1 == 0,], points(Xvar, Yvar, col = 1)) # first line
 with(d[d$param1 == 1,], points(Xvar, Yvar, col = 2)) # second line

}

par(mfrow=c(2,2))
plyr::d_ply(data, "Subject", plot_one)

--
View this message in context: http://r.789695.n4.nabble.com/Loop-for-multiple-plots-in-figure-tp4634390p4634482.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list