tags:

views:

69

answers:

2

Hi ,

This is my data set what i am trying to do is draw a graph TAD Vs IPRE,DV,PRED as a whole which i have no issues in producing them.

Second part is I am trying to produce an individual graph for ID (n=35) so 35 graph for (TAD Vs IPRE,DV,PRED)

Third Part is to try and produce a graph based on Ward (TAD Vs IPRE,DV,PRED) which will have 5 graphs.

Tried few options and struggling to write a code...no luck (new to R). Can some body help me on this?

Thanks in Advance.

ID TIME TAD AMT BL WARD IPRE DV PRED RES WRES
1 0 0 0 0 0 0 0.01 0 0 0.95
1 0.01 0 20 0 0 0 0 0 0 0
1 1 0.99 0 0 0 0.11 0.13 0.02 0.11 3.85
1 2 1.99 0 0 0 0.11 0.12 0.02 0.1 4
1 4 3.99 0 0 0 0.1 0.07 0.02 0.05 -0.48
1 6 5.99 0 0 0 0.09 0.03 0.02 0.02 -3.07
1 8 7.99 0 0 0 0.08 0.04 0.02 0.03 -2.04
1 24 24 0 0 0 0.04 0.03 0.01 0.02 -0.32
1 48 0 20 0 0 0.02 0 0.01 0 0
1 49 1 0 0 0 0.12 0.25 0.02 0.23 3.07
1 50 2 0 0 0 0.12 0.26 0.02 0.23 3.33
1 52 4 0 0 0 0.11 0.17 0.02 0.15 1.99
1 54 6 0 0 0 0.1 0.09 0.02 0.07 0.7
1 56 8 0 0 0 0.09 0.05 0.02 0.04 -0.03
1 72 24 0 0 0 0.05 0.01 0.01 0 -1.09
2 0 0 20 0 0 0 0 0 0 0
2 1 1 0 0 0 0.01 0 0.02 -0.02 -1.09
2 2 2 0 0 0 0.01 0.01 0.02 -0.01 -0.55
2 4 4 0 0 0 0.01 0.01 0.02 -0.01 -0.58
2 6 6 0 0 0 0.01 0 0.01 -0.01 -0.71
2 8 8 0 0 0 0.01 0 0.01 -0.01 -0.63
2 24 24 0 0 0 0.01 0 0.01 0 -0.44
2 72 0 20 0 0 0 0 0 0 0
2 73 1 0 0 0 0.02 0.04 0.02 0.02 2.51
2 74 2 0 0 0 0.01 0.02 0.02 0 0.02
2 76 4 0 0 0 0.01 0.01 0.02 -0.01 -0.05
2 78 6 0 0 0 0.01 0.01 0.01 -0.01 -0.09
2 80 8 0 0 0 0.01 0.02 0.01 0 0.14
2 96 24 0 0 0 0.01 0 0.01 0 0
3 0 0 20 0 0 0 0 0 0 0
3 1 1 0 0 0 0.04 0.02 0.02 0 -0.61
3 2 2 0 0 0 0.04 0.03 0.02 0.01 -0.16
3 4 4 0 0 0 0.03 0.08 0.02 0.06 5.95
3 6 6 0 0 0 0.03 0.01 0.01 0 -1.29
3 8 8 0 0 0 0.03 0.01 0.01 0 -1.64
3 24 24 0 0 0 0.01 0 0.01 0 -2.32
4 0 0 20 0 0 0 0 0 0 0
4 1 1 0 0 0 0.08 0.1 0.02 0.09 1.45
4 2 2 0 0 0 0.07 0.13 0.02 0.12 4.73
4 4 4 0 0 0 0.07 0.13 0.02 0.12 5.94
4 6 6 0 0 0 0.06 0.07 0.01 0.06 -0.09
4 8 8 0 0 0 0.06 0.07 0.01 0.06 0.21
4 24 24 0 0 0 0.03 0.02 0.01 0.02 -3
4 72 72 0 0 0 0 0.01 0 0.01 0.98
4 72 0 20 0 0 0 0 0 0 0
4 73 0.99 0 0 0 0.08 0.09 0.02 0.07 0.51
4 74 1.99 0 0 0 0.08 0.06 0.02 0.04 0.02
4 76 3.99 0 0 0 0.07 0.04 0.02 0.02 -0.34
4 78 5.99 0 0 0 0.06 0.02 0.01 0 -0.71
4 80 7.99 0 0 0 0.06 0.02 0.01 0.01 -0.65
4 96 24 0 0 0 0.03 0.01 0.01 0 -1.02
5 0 0 20 0 0 0 0 0 0 0
5 1 1 0 0 0 0.06 0.08 0.02 0.07 2.05
5 2 2 0 0 0 0.06 0.07 0.02 0.05 1.17
5 4 4 0 0 0 0.05 0.06 0.02 0.04 0.56
5 6 6 0 0 0 0.05 0.08 0.01 0.07 3.47
5 24 24 0 0 0 0.02 0.01 0.01 0 -4.17
6 0 0 20 0 0 0 0 0 0 0
6 1 1 0 0 0 0.05 0 0.02 0 0
6 2 2 0 0 0 0.04 0.01 0.02 -0.01 -2.99
6 4 4 0 0 0 0.04 0.05 0.02 0.03 0.98
6 6 6 0 0 0 0.04 0.06 0.01 0.04 2.92
6 8 8 0 0 0 0.03 0.05 0.01 0.04 2.47
7 0 0 0 0 0 0 0 0 0 0.31
7 0 0 20 0 0 0 0 0 0 0
7 1 1 0 0 0 0.17 0.28 0.02 0.26 8.57
7 2 2 0 0 0 0.16 0.3 0.02 0.28 11
7 4 4 0 0 0 0.15 0.19 0.02 0.18 3.63
7 6 6 0 0 0 0.14 0.14 0.02 0.12 -0.72
7 8 8 0 0 0 0.13 0.11 0.02 0.1 -2.03
7 24 24 0 0 0 0.07 0.04 0.01 0.04 -4.53
8 0 0 20 0 0 0 0 0 0 0
8 1 1 0 0 0 0.02 0.03 0.02 0.02 1.64
8 2 2 0 0 0 0.02 0.01 0.02 -0.01 -0.66
8 4 4 0 0 0 0.01 0.02 0.02 0 0.16
8 6 6 0 0 0 0.01 0 0.01 -0.01 -1.17
8 8 8 0 0 0 0.01 0.01 0.01 0 -0.28
8 24 24 0 0 0 0.01 0.01 0.01 0 -0.07
9 0 0 20 0 3 0 0 0 0 0
9 1 1 0 0 3 0.05 0.09 0.02 0.07 4.59
9 2 2 0 0 3 0.04 0.06 0.02 0.04 2.24
9 4 4 0 0 3 0.04 0.03 0.02 0.01 -0.63
9 6 6 0 0 3 0.04 0.02 0.01 0 -1.64
9 8 8 0 0 3 0.03 0.01 0.01 -0.01 -2.88
9 24 24 0 0 3 0.02 0 0.01 0 0
10 0 0 20 0 3 0 0 0 0 0
10 1 1 0 0 3 0.02 0.04 0.02 0.02 1.78
10 2 2 0 0 3 0.02 0.01 0.02 -0.01 -0.54
10 4 4 0 0 3 0.02 0.01 0.02 -0.01 -0.86
10 6 6 0 0 3 0.01 0.02 0.01 0 0.37
10 8 8 0 0 3 0.01 0.01 0.01 -0.01 -1.04
10 24 24 0 0 3 0.01 0 0.01 0 0
11 0 0 0 0 3 0 0 0 0 -0.26
11 0.01 0 20 0 3 0 0 0 0 0
11 1 0.99 0 0 3 0.01 0.01 0.02 -0.01 -0.41
11 2 1.99 0 0 3 0.01 0.01 0.02 -0.01 -0.24
11 4 3.99 0 0 3 0.01 0.01 0.02 -0.01 -0.16
11 6 5.99 0 0 3 0.01 0.01 0.02 -0.01 -0.21
11 8 7.99 0 0 3 0.01 0.01 0.02 -0.01 -0.13
11 24 24 0 0 3 0 0 0.01 -0.01 -0.27
12 0 0 20 0 3 0 0 0 0 0
12 1 1 0 0 3 0.01 0.01 0.02 -0.01 0.02
12 2 2 0 0 3 0.01 0.01 0.02 -0.01 -0.08
12 4 4 0 0 3 0.01 0.01 0.02 -0.01 -0.23
12 6 6 0 0 3 0.01 0.01 0.01 -0.01 -0.45
12 8 8 0 0 3 0.01 0.01 0.01 0 -0.04
12 24 24 0 0 3 0 0 0.01 0 0
13 0 0 20 0 2 0 0 0 0 0
13 1 1 0 0 2 0.04 0.08 0.02 0.06 5.23
13 2 2 0 0 2 0.04 0.02 0.02 0.01 -0.42
13 4 4 0 0 2 0.04 0 0.02 -0.01 -2.33
13 6 6 0 0 2 0.03 0.01 0.01 -0.01 -2.01
13 8 8 0 0 2 0.03 0 0.01 0 0
13 24 24 0 0 2 0.02 0 0.01 0 0
14 0 0 20 0 3 0 0 0 0 0
14 1 1 0 0 3 0.01 0.01 0.02 -0.01 -0.39
14 2 2 0 0 3 0.01 0.01 0.02 -0.01 -0.49
14 4 4 0 0 3 0.01 0.01 0.02 0 0.33
14 6 6 0 0 3 0.01 0.01 0.01 0 -0.04
14 8 8 0 0 3 0.01 0.01 0.01 0 0.17
14 24 24 0 0 3 0 0 0.01 0 0
15 0 0 20 0 1 0 0 0 0 0
15 1 1 0 0 1 0.01 0.01 0.02 -0.01 -0.3
15 2 2 0 0 1 0.01 0.01 0.02 -0.01 -0.41
15 4 4 0 0 1 0 0 0.02 0 0
15 6 6 0 0 1 0 0 0.01 0 0
15 8 8 0 0 1 0 0 0.01 0 0
15 24 24 0 0 1 0 0 0.01 0 0
16 0 0 20 0 1 0 0 0 0 0
16 1 1 0 0 1 0 0 0.02 -0.02 -0.54
16 2 2 0 0 1 0 0 0.02 -0.01 -0.45
16 4 4 0 0 1 0 0 0.02 -0.01 -0.26
16 6 6 0 0 1 0 0.01 0.01 -0.01 0.05
16 8 8 0 0 1 0 0 0.01 -0.01 -0.12
16 24 24 0 0 1 0 0 0.01 0 -0.02
18 0 0 20 0 1 0 0 0 0 0
18 1 1 0 0 1 0.02 0.01 0.02 -0.01 -1.03
18 2 2 0 0 1 0.02 0.02 0.02 0 0.01
18 4 4 0 0 1 0.02 0 0.02 -0.01 -1.27
18 6 6 0 0 1 0.02 0.02 0.01 0 0.59
18 8 8 0 0 1 0.02 0.02 0.01 0 0.57
18 24 24 0 0 1 0.01 0.02 0.01 0.01 2.69
19 0 0 20 0 1 0 0 0 0 0
19 1 1 0 0 1 0.01 0 0.02 -0.02 -0.67
19 2 2 0 0 1 0.01 0 0.02 -0.01 -0.56
19 4 4 0 0 1 0.01 0.01 0.02 -0.01 -0.03
19 6 6 0 0 1 0.01 0.01 0.01 -0.01 -0.01
19 8 8 0 0 1 0.01 0.01 0.01 -0.01 0.15
19 24 24 0 0 1 0 0.01 0.01 0 0.49
20 0 0 20 0 1 0 0 0 0 0
20 1 1 0 0 1 0.01 0.03 0.02 0.01 0.98
20 2 2 0 0 1 0.01 0.02 0.02 0 0.31
20 4 4 0 0 1 0.01 0.01 0.02 -0.01 -0.49
20 6 6 0 0 1 0.01 0.01 0.01 -0.01 -0.53
20 8 8 0 0 1 0.01 0.01 0.01 -0.01 -0.59
20 24 24 0 0 1 0 0 0.01 0 -0.39
22 0 0 20 0 1 0 0 0 0 0
22 1 1 0 0 1 0.01 0.01 0.02 -0.01 -0.65
22 2 2 0 0 1 0.01 0.01 0.02 -0.01 -0.18
22 4 4 0 0 1 0.01 0.02 0.02 0 0.53
22 6 6 0 0 1 0.01 0.01 0.01 -0.01 -0.16
22 8 8 0 0 1 0.01 0.01 0.01 -0.01 -0.18
22 24 24 0 0 1 0 0 0.01 0 0
23 0 0 20 0 1 0 0 0 0 0
23 1 1 0 0 1 0.02 0.02 0.02 0 -0.47
23 2 2 0 0 1 0.02 0.05 0.02 0.03 2.6
23 4 4 0 0 1 0.02 0.02 0.02 0.01 0.21
23 6 6 0 0 1 0.02 0.01 0.01 0 -0.47
23 8 8 0 0 1 0.02 0.01 0.01 0 -0.86
23 24 24 0 0 1 0.01 0 0.01 0 -1.38
24 0 0 0 0 1 0 0 0 0 0.16
24 0.01 0 20 0 1 0 0 0 0 0
24 1 0.99 0 0 1 0.01 0.02 0.02 0 0.56
24 2 1.99 0 0 1 0.01 0.01 0.02 -0.01 -0.53
24 4 3.99 0 0 1 0.01 0.01 0.02 -0.01 -0.02
24 6 5.99 0 0 1 0.01 0.01 0.02 -0.01 -0.48
24 8 7.99 0 0 1 0.01 0.01 0.02 -0.01 -0.39
24 24 24 0 0 1 0.01 0 0.01 -0.01 -0.59
25 0 0 20 0 2 0 0 0 0 0
25 1 1 0 0 2 0.06 0.1 0.02 0.09 4.51
25 2 2 0 0 2 0.05 0.07 0.02 0.05 1.54
25 4 4 0 0 2 0.05 0.06 0.02 0.05 1.2
25 6 6 0 0 2 0.05 0.06 0.01 0.05 1.58
25 8 8 0 0 2 0.04 0.02 0.01 0.01 -2.52
25 24 24 0 0 2 0.02 0 0.01 0 -4.48
26 0 0 20 0 2 0 0 0 0 0
26 1 1 0 0 2 0.15 0.12 0.02 0.1 -2.99
26 2 2 0 0 2 0.15 0.24 0.02 0.22 9.42
26 4 4 0 0 2 0.14 0.22 0.02 0.21 9.35
26 6 6 0 0 2 0.12 0.17 0.01 0.16 5.55
26 8 8 0 0 2 0.11 0.14 0.01 0.12 2.46
26 24 24 0 0 2 0.06 0.01 0.01 0 -12.9
28 0 0 20 0 2 0 0 0 0 0
28 1 1 0 0 2 0.1 0.01 0.02 -0.01 -5.13
28 2 2 0 0 2 0.09 0.03 0.02 0.02 -2.94
28 4 4 0 0 2 0.08 0.18 0.02 0.17 13.7
28 6 6 0 0 2 0.08 0.07 0.01 0.06 2.22
28 8 8 0 0 2 0.07 0.04 0.01 0.03 -1.01
28 24 24 0 0 2 0.04 0 0.01 0 0
29 0 0 20 0 2 0 0 0 0 0
29 1 1 0 0 2 0.01 0.01 0.02 -0.01 -0.46
29 2 2 0 0 2 0.01 0.01 0.02 -0.01 -0.22
29 4 4 0 0 2 0.01 0 0.02 0 0
29 6 6 0 0 2 0 0 0.01 0 0
29 8 8 0 0 2 0 0 0.01 0 0
29 24 24 0 0 2 0 0 0.01 0 0
30 0 0 20 0 0 0 0 0 0 0
30 1 1 0 0 0 0.07 0 0.02 0 0
30 2 2 0 0 0 0.07 0.01 0.02 -0.01 -4.61
30 4 4 0 0 0 0.06 0.09 0.02 0.08 4.77
30 6 6 0 0 0 0.06 0.09 0.01 0.07 5.02
30 8 8 0 0 0 0.05 0.03 0.01 0.01 -1.98
30 24 24 0 0 0 0.03 0.04 0.01 0.03 3.14
31 0 0 20 0 4 0 0 0 0 0
31 1 1 0 0 4 0 0 0.02 -0.01 -0.26
31 2 2 0 0 4 0 0 0.02 -0.01 -0.46
31 4 4 0 0 4 0 0 0.02 -0.01 -0.27
31 6 6 0 0 4 0 0 0.01 -0.01 -0.15
31 8 8 0 0 4 0 0 0.01 -0.01 -0.21
31 24 24 0 0 4 0 0 0.01 0 0.06
32 0 0 20 0 4 0 0 0 0 0
32 1 1 0 0 4 0 0 0.02 0 0
32 2 2 0 0 4 0 0 0.02 -0.01 -0.23
32 4 4 0 0 4 0 0 0.02 -0.02 -0.62
32 6 6 0 0 4 0 0 0.01 -0.01 -0.38
32 24 24 0 0 4 0 0 0.01 0 0.05
33 0 0 20 0 4 0 0 0 0 0
33 1 1 0 0 4 0 0 0.02 -0.01 -0.32
33 2 2 0 0 4 0 0 0.02 -0.01 -0.29
33 4 4 0 0 4 0 0 0.02 -0.01 -0.37
33 6 6 0 0 4 0 0.01 0.01 -0.01 -0.08
33 8 8 0 0 4 0 0 0.01 -0.01 -0.29
33 24 24 0 0 4 0 0 0.01 0 0.06
34 0 0 20 0 4 0 0 0 0 0
34 1 1 0 0 4 0.01 0.01 0.02 -0.01 0.04
34 2 2 0 0 4 0.01 0 0.02 -0.01 -0.49
34 4 4 0 0 4 0.01 0 0.02 -0.01 -0.41
34 6 6 0 0 4 0.01 0 0.01 -0.01 -0.36
34 8 8 0 0 4 0.01 0.01 0.01 -0.01 -0.15
34 24 24 0 0 4 0 0.01 0.01 0 0.69
35 0 0 20 0 4 0 0 0 0 0
35 1 1 0 0 4 0 0 0.02 -0.02 -0.39
35 2 2 0 0 4 0 0.01 0.02 -0.01 -0.1
35 4 4 0 0 4 0 0 0.02 -0.01 -0.26
35 6 6 0 0 4 0 0 0.01 -0.01 -0.24
35 8 8 0 0 4 0 0 0.01 -0.01 -0.3
35 24 24 0 0 4 0 0 0.01 -0.01 -0.46

Kind Regards

rcmoulirc

A: 

You can easily subset your data frame and plot only that

For instance, let's say that your data frame is called df:

df[df$ID==1,]

will return only the lines with ID=1

Put this in a loop and you have your graphs

for (i in 1:35) # Or, even better 1:(max(df$ID))
    {
    X11()
    tmp <- df[df$ID == i,]
    # Plot whatever you need to plot
    }
nico
A: 

Here's some code using the amazing ggplot2 package that produces the kinds of graphs I would want in this case. Check out the documentation and Hadley's website to tweak them.

#Assume ID, and Ward are factors, and WRES. shouldn't be
pkso$ID<-as.factor(pkso$ID)
pkso$WARD<-as.factor(pkso$WARD)
pkso$WRES<-as.numeric(pkso$WRES.)

#display clean data for SO fans
dput(pkso)

library(ggplot2)

#draw a graph TAD Vs IPRE,DV,PRED as a whole which i have no issues in producing them.
#first melt the data into a narrow format, then plot
pksomelt<-melt(pkso, id.vars=c("ID","TIME","TAD","AMT","BL","WARD"))
pksomelt$value<-as.numeric(pksomelt$value)
#now subset that data for what we want
pksomelt<-subset(pksomelt,variable %in% c("IPRE","DV","PRED"))
#now plot, using facet_wrap to seperate variables
pkplot1<-ggplot(pksomelt, aes(TAD, value)) + 
        geom_point() +
        scale_shape(solid = FALSE) + 
        facet_wrap( ~ variable)

print(pkplot1)
#Second part is I am trying to produce an individual graph for ID (n=35) so 35 graph for (TAD Vs IPRE,DV,PRED)
#so, for an individual plot
pkplot2<-ggplot(subset(pksomelt, ID == "1"), aes(TAD, value)) + 
        geom_point() +
        scale_shape(solid = FALSE) + 
        facet_wrap( ~ variable)

print(pkplot2)
#  or, for presenting, you could do all 35 spread across 6 plots, but seperated, by using facet_grid
i<-ceiling(max(as.numeric(pksomelt$ID))/6)  #  Calculate number of ID's per plot

pkplot3<-ggplot(subset(pksomelt, as.numeric(pksomelt$ID) > (i*0) & as.numeric(pksomelt$ID) < (i*1)+1), 
                aes(TAD, value)) + 
        geom_point() +
        scale_shape(solid = FALSE) + 
        facet_grid(ID ~ variable)

print(pkplot3)

pkplot4<-ggplot(subset(pksomelt, as.numeric(pksomelt$ID) > (i*1) & as.numeric(pksomelt$ID) < (i*2)+1), 
                aes(TAD, value)) + 
        geom_point() +
        scale_shape(solid = FALSE) + 
        facet_grid(ID ~ variable)

print(pkplot4) #  ect etc
#Third Part is to try and produce a graph based on Ward (TAD Vs IPRE,DV,PRED) which will have 5 graphs.
#Again, use Facet_grid to seperate different wards, let's also add lines to show it's possible
pkplot5<-ggplot(pksomelt, aes(TAD, value)) + 
        geom_point(aes(colour=ID)) + geom_line(aes(colour=ID)) + 
        scale_shape(solid = FALSE) + 
        facet_grid(WARD ~ variable, scales="free")

print(pkplot5)
PaulHurleyuk