0

I am using R to make a plot of my data.

I have two files:

1.
V1     V2
12.33  124.23
13.45  196.45
12.34  124.34
12.34  124.34

2.
V1 V2 
2  345.56
1  0.123
2  34.34
3  234.45

I want to make separate graphs of the first column of the first file based on the first column of the second file. That is in lattice library:

y=V1 of the first file
x=V2 of the second file
z=V1 of the second file

Using this code:

xyplot(y~x | z, pch=".")

I have obtained the graphs I wanted but now, my problem is that I want to write the number of each graph based on z, that is for example on top of graph one, I want to have n=1.

How I could do that?

Thank you in advance.

John Paul
  • 12,196
  • 6
  • 55
  • 75
Lucia
  • 901
  • 1
  • 11
  • 16

1 Answers1

1

If you convert your variable "z" to a factor using as.factor then lattice should automatically make the headers of each graph the name of that level.

so something like

z <- as.factor(z)
xyplot(y~x | z, pch=".")

should change the z's in the headers to the numbers which z represents.

If you want "n = 1" etc then changing the names of the levels will do that;

z <- as.factor(z)
levels(z)=c("n = 1","n = 2", "n = 3")  # and so on until you have named every level
xyplot(y~x | z, pch=".")
Adam Kimberley
  • 879
  • 5
  • 12