views:

438

answers:

1

I have the following setup:

emp <- structure(list(s = structure(c(1L, 2L, 2L, 2L, 7L, 7L, 3L, 4L, 4L, 4L, 4L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 10L, 5L, 5L, 6L), .Label = c("8", "24", "31", "78", "135", "142", "30", "98", "117", "123"), class = "factor", scores = structure(c(1, 2, 14, 3, 5, 17, 18, 20, 11, 13), .Dim = 10L, .Dimnames = list(c("8", "24", "30", "31", "78", "98", "117", "123", "135", "142")))), t = structure(c(6L, 1L, 2L, 4L, 7L, 9L, 3L, 1L,  2L, 4L, 5L, 8L, 9L, 10L, 7L, 8L, 9L, 11L, 9L, 1L, 4L, 1L), .Label = c("8", "24", "40", "78", "135", "142", "30", "98", "117", "119", "123" ), class = "factor", scores = structure(c(1, 2, 14, 4, 5, 17, 18, 19, 20, 11, 13), .Dim = 11L, .Dimnames = list(c("8", "24", "30", "40", "78", "98", "117", "119", "123", "135", "142")))), V1 = c(3L, 1L, 9L, 4L, 1L, 107L, 2L, 5L, 3L, 1L, 2L, 1L,  6L, 14L, 20L, 1L, 4L, 1L, 2L, 3L, 2L, 2L)), .Names = c("s", "t", "V1"), row.names = c(NA, -22L), class = "data.frame")
o <- c(8L, 24L, 31L, 40L, 78L, 80L, 85L, 94L, 104L, 113L, 135L, 136L, 142L, 30L, 54L, 91L, 98L, 117L, 119L, 123L, 9L, 34L, 97L, 126L,  140L, 13L, 75L, 92L, 134L, 138L, 141L, 6L, 12L, 22L, 44L, 48L, 51L, 57L, 64L, 79L, 84L, 88L, 93L, 100L, 115L, 124L, 129L, 132L,  143L, 144L, 2L, 10L, 14L, 15L, 16L, 17L, 19L, 35L, 39L, 41L, 50L, 52L, 53L, 58L, 61L, 66L, 67L, 68L, 71L, 72L, 73L, 76L, 96L, 99L, 101L, 106L, 109L, 114L, 121L, 127L, 128L, 131L, 137L, 145L, 146L, 148L, 150L, 4L, 18L, 23L, 28L, 29L, 32L, 37L, 38L, 65L, 82L, 90L, 102L, 105L, 107L, 111L, 122L, 130L, 133L, 139L, 147L, 3L, 5L, 7L, 11L, 21L, 27L, 33L, 43L, 45L, 46L, 47L, 49L, 55L, 56L, 59L, 60L, 62L, 63L, 69L, 70L, 77L, 83L, 87L, 89L, 103L, 108L, 112L, 116L, 118L, 120L, 125L, 149L, 151L, 1L, 20L, 25L, 26L, 36L, 42L, 74L, 81L, 86L, 95L, 110L)

emp$s <- reorder(factor(emp$s),match(emp$s,o))
emp$t <- reorder(factor(emp$t),match(emp$t,o))
qq <- ggplot(emp,aes(x=s,y=t))
qq + geom_tile(aes(fill=log(V1)))+theme_bw()+
scale_fill_gradient(low="white",high="black")+
opts(axis.text.x=theme_text(angle=-90, hjust=0, size=5),
     axis.text.y=theme_text(vjust=0, size=5),
     panel.grid.minor = theme_blank(),
     panel.grid.major = theme_blank())

This produces the following:

alt text

I would like to include a vertical line just after 142 and before 30. (Note, I need to keep these values as a factor.) I've been considering two options:

  • vline: I only am able to put the line on 142 and on 30, but not between them.
  • grid stuff: I feel like the ideal solution is to introduce a grid.major or something.

Any ideas?

+4  A: 

I'm not sure if this is what you mean:

p <- ggplot(emp, aes(x=s, y=t)) +
     geom_tile(aes(fill=log(V1))) +
     theme_bw() +
     scale_fill_gradient(low="white", high="black") +
     opts(axis.text.x=theme_text(angle=-90, hjust=0, size=5),
          axis.text.y=theme_text(vjust=0, size=5),
          panel.grid.minor=theme_blank(),
          panel.grid.major=theme_blank()) +
     geom_vline(xintercept=which(levels(emp$s) %in% c("142", "30")) + c(0.25, -0.25))
print(p)

ggplot2 output

rcs
Almost. I wanted a single line exactly in the middle of those two, which only required small modification to your code. Thanks! I got too buried in trying to figure out how to customize grids...
Christopher DuBois