[R] How do I perform conditional annotation of lattice panel plots?

Duncan Mackay dulcalma at bigpond.com
Wed Jan 8 03:25:42 CET 2014


Hi George

If you did not want a line through the point try this

xyplot(Activity ~ Day | Subject, data = Data,pch =
ifelse(is.na(Data$EventA), 1,16), col = ifelse(is.na(Data$EventA), 4,2))

You could make a column of it otherwise change EventA to numeric - easier to
work with

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mackay at northnet.com.au

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of Chen, George
Sent: Wednesday, 8 January 2014 00:07
To: r-help at r-project.org
Subject: [R] How do I perform conditional annotation of lattice panel plots?

My apologies for asking this question that may have been asked before. I am
trying to plot activity dependent on time conditioned by the subject. Code
for sample data below.

So I have something like this

xyplot(Activity~Time|Subject).
This works fine, but now I want to show where on these activity curves Event
A occurs. This is to explore the relationship between A and activity.

I tried this:

xyplot(EventA+Activity~Time|Subject)

but then the numerical ordering gets out of order.
Ideally Event A could be denoted by a vertical line cutting through the
curve at the day Event A occurred, but some other way to denote it would be
great!

Here is my sample data as R code:

Subject<-c(1,1,1,1,1,1,2,2,2,2,2,2,3,3,3,3,3,3,4,4,4,4,4,4)
Day<-c(1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6)
Activity<-c(2,3,4,3,7,4,5,8,2,8,4,6,2,5,3,8,9,5,6,3,4,5,6,7)
EventA<-c("Yes",NA,"Yes",NA,NA,NA,"Yes",NA,NA,NA,NA,NA,
          "Yes",NA,NA,NA,NA,NA,NA,NA,"Yes",NA,NA,NA)
Data<-data.frame(cbind(Subject,Day,Activity,EventA))

  Subject Day Activity EventA
1        1   1        2    Yes
2        1   2        3   <NA>
3        1   3        4    Yes
4        1   4        3   <NA>
5        1   5        7   <NA>
6        1   6        4   <NA>
7        2   1        5    Yes
8        2   2        8   <NA>
9        2   3        2   <NA>
10       2   4        8   <NA>
11       2   5        4   <NA>
12       2   6        6   <NA>
13       3   1        2    Yes
14       3   2        5   <NA>
15       3   3        3   <NA>
16       3   4        8   <NA>
17       3   5        9   <NA>
18       3   6        5   <NA>
19       4   1        6   <NA>
20       4   2        3   <NA>
21       4   3        4    Yes
22       4   4        5   <NA>
23       4   5        6   <NA>
24       4   6        7   <NA>
Any ideas on how to do this would be appreciated!

Thanks very much in advance!


This email message may contain legally privileged and/or confidential
information.  If you are not the intended recipient(s), or the employee or
agent responsible for the delivery of this message to the intended
recipient(s), you are hereby notified that any disclosure, copying,
distribution, or use of this email message is prohibited.  If you have
received this message in error, please notify the sender immediately by
e-mail and delete this email message from your computer. Thank you.
	[[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list