Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

coplot in R - how to tell which plot is which

Tags:

plot

r

loess

I am using coplot in R to plot some conditioning plots:

coplot(var1 ~ var2 | var3, data=dtb, number=5, overlap=.1, panel=function(x,y, col, pch) {idx = order(x); lines(x[idx], predict(loess(y ~ x))[idx], pch = pch, col = col)})

How can one tell which plot corresponds to which "bucket" of the conditioning variable, in this case var3?

> dput(dtb)
structure(list(var1 = 1:50, var2 = c(50L, 49L, 48L, 47L, 46L, 
45L, 44L, 43L, 42L, 41L, 40L, 39L, 38L, 37L, 36L, 35L, 34L, 33L, 
32L, 31L, 30L, 29L, 28L, 27L, 26L, 25L, 24L, 23L, 22L, 21L, 20L, 
19L, 18L, 17L, 16L, 15L, 14L, 13L, 12L, 11L, 10L, 9L, 8L, 7L, 
6L, 5L, 4L, 3L, 2L, 1L), var3 = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 
8L, 9L, 10L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 1L, 2L, 
3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 
8L, 9L, 10L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L)), .Names = c("var1", 
"var2", "var3"), row.names = c(NA, -50L), class = "data.frame")
like image 879
Alex Avatar asked Jan 28 '13 18:01

Alex


People also ask

How do I read Coplot in R?

Regarding reading the chart, you would read the columns as representing the three depth groups (left to right) and the rows as representing the four mag groups (bottom to top). Thus, as you read up the chart you're progressively slicing the data into groups of observations with increasing magnitudes.

What is a co plot?

Definition of 'coplot' 1. to plot together on the same graph. 2. to construct the plot of (a literary work) together.

What is a Coplot in R?

The coplot() function plots two variables but each plot is conditioned ( | ) by a third variable. This third variable can be either numeric or a factor. As an example, let's look at how the relationship between the number of flowers ( flowers variable) and the weight of petunia plants changes dependent on leafarea .


1 Answers

Apparently it is left to right and bottom to top, which means it is much easier to read if you set rows=1 :

# determine how many levels in var3
num <- length(unique(dtb$var3))

# plot in one row using all levels of var3
coplot(var1 ~ var2 | var3, data=dtb, 
number=num, 
overlap=.1, 
col=rainbow(num), 
type="o",           # plot symbols and lines
cex=2,              # make symbols larger
pch=as.character(c(seq(from=1,to=(num-1)),"T")), # use chars as symbols
rows=1)                                          # as.character not required 
                                                 # due to "T"

enter image description here

# plot in two rows
coplot(var1 ~ var2 | var3, data=dtb, 
number=num, 
overlap=.1, 
col=rainbow(num), 
type="o",           # plot symbols and lines
cex=2,              # make symbols larger
pch=as.character(c(seq(from=1,to=(num-1)),"T")), # use chars as symbols
rows=2)                                          # as.character not required 
                                                 # due to "T"

enter image description here

like image 146
MattBagg Avatar answered Oct 19 '22 18:10

MattBagg