# Re: [R] Coloring Stripchart Points, or Better, Lattice Equivalent

From: Bryan Hanson <hanson_at_depauw.edu>
Date: Sun, 22 Jun 2008 10:43:06 -0400

When plotting all the data (5th panel), col & sym don't seem to be passed correctly, as the (random) first value for col & sym are used for all points (run the code, then run it again, you'll see how the 5th panel changes depending upon col & sym for the first data point). The 5th panel should ideally be the "sum" of the 4 panels above, keeping col & sym intact.

Also, I would rather have this in lattice or ggplot2, if anyone sees how to convert it.

Thanks once again, several of you have made very useful suggestions off list. Bryan

samples <- 100 # must be even
index <- round(runif(samples, 1, 100)) # set up data resp <- rbinom(samples, 1, 0.5)
yr <- rep(c("2005", "2006"), samples/2)

```all <- data.frame(index, resp, yr)
all\$sym <- ifelse(all\$resp == 1, 1, 3)
all\$col <- ifelse(all\$yr == 2005, "red", "blue")
```
all\$count <- rep(1, length(all\$index))
all <- all[order(all\$index, all\$yr, all\$resp),] # for easier inspection row.names(all) <- c(1:samples) # for easier inspection

one <- all[(all\$yr == 2005 & all\$resp == 0),] # First 2005/0 at top two <- all[(all\$yr == 2005 & all\$resp == 1),] # Then 2005/1 three <- all[(all\$yr == 2006 & all\$resp == 0),] # Now 2006/0 four <- all[(all\$yr == 2006 & all\$resp == 1),] # Finally 2006/1

par(mfrow = c(5, 1))
par(plt = c(0.1, 0.9, 0.25, 0.75))
stripchart(one\$index, method = "stack", ylim = c(0,10), xlim = c(1,100), col
= one\$col, pch = one\$sym)

mtext("2005/0", side = 3)
stripchart(two\$index, method = "stack", ylim = c(0,10), xlim = c(1,100), col
= two\$col, pch = two\$sym)

mtext("2005/1", side = 3)
stripchart(three\$index, method = "stack", ylim = c(0,10), xlim = c(1,100), col = three\$col, pch = three\$sym)
mtext("2006/0", side = 3)

stripchart(four\$index, method = "stack", ylim = c(0,10), xlim = c(1,100), col = four\$col, pch = four\$sym)
mtext("2006/1", side = 3)
stripchart(all\$index, method = "stack", ylim = c(0,10), xlim = c(1,100), col
= all\$col, pch = all\$sym)
mtext("col & sym always taken from 1st data point when all data is plotted!", side = 3)

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. Received on Sun 22 Jun 2008 - 15:06:29 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 22 Jun 2008 - 17:30:54 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.