On 7/18/2011 9:23 PM, Sigrid wrote:
Hi
I apologize for not providing reproducible codes more clearly, and I hope
this will be more understandable.

I have 14 lines (7 per facet that I would like to add). I will provide you
with six of the lines from the data as that should  enough data to work
with, and also result in less plotting for all of us. These value are from a
previously conducted ancova, so not based on simple linear regression.

Line #    Country          Treatment    Intercept       Slope
1          Low           A               81.47   47.267
2          Low           B               31.809 20.234
3          Low           C               69.892 33.717
4          High          A               67.024 47.267
5          High          B               17.357 20.234
6          High          C               105.107        33.717

Is this (above) a data.frame? If not, can you get it into one? If so, then adding all the lines at once is easy. Lets say that the data.frame is named "lines" (Note that I changed the capitalization of country and treatment to match what was in test.)

> lines
  Line # country treatment Intercept  Slope
1      1     Low         A    81.470 47.267
2      2     Low         B    31.809 20.234
3      3     Low         C    69.892 33.717
4      4    High         A    67.024 47.267
5      5    High         B    17.357 20.234
6      6    High         C   105.107 33.717
> dput(lines)
structure(list(`Line #` = 1:6, country = structure(c(2L, 2L,
2L, 1L, 1L, 1L), .Label = c("High", "Low"), class = "factor"),
    treatment = structure(c(1L, 2L, 3L, 1L, 2L, 3L), .Label = c("A",
    "B", "C"), class = "factor"), Intercept = c(81.47, 31.809,
    69.892, 67.024, 17.357, 105.107), Slope = c(47.267, 20.234,
    33.717, 47.267, 20.234, 33.717)), .Names = c("Line #", "country",
"treatment", "Intercept", "Slope"), class = "data.frame", row.names = c(NA,
-6L))


From the help that I got here, i was able to make the plot I wanted.
ggplot(data = test, aes(x = year, y = total, colour = treatment)) +
          geom_point(aes(shape = treatment)) +
        facet_wrap(~country) +
          scale_colour_grey(breaks=c('A','B','C','D','E','F','G'),
                  labels=c('label A','label B','label C','label D',
                          'label E','label F','label G')) +
          scale_shape_manual(breaks=c('A','B','C','D','E','F','G'),
                  labels=c('label A','label B','label C','label D',
                          'label E','label F','label G'),
                  values = c(0, 1, 2, 3, 4, 5, 6)) +
          scale_y_continuous("number of votes") +
          scale_x_continuous("Years", breaks=1:4) +
          theme_bw()+

You can just add

geom_abline(aes(intercept = Intercept, slope = Slope, colour = treatment), data = lines)

This says to use the data from the lines data.frame, plotting a line for each row of the data set. The line will be colored based on the value of the treatment variable (with the mapping defined the same as for the points). The lines will also be faceted according to country (the facet_wrap affects all geoms).

And I added line #1 and # 4 using the abline command.

+geom_abline(intercept = 81.47, slope=47.267, colour = "black", size = 0.5,
subset = .(country == 'low'))+ geom_abline(intercept = 67.024, slope=47.267,
colour = " grey", size = 0.5, subset = .(country== 'high'))

How can I make the lines correspond with the descriptions on the right side
of the graph more clearly?

--
View this message in context: 
http://r.789695.n4.nabble.com/grey-colored-lines-and-overwriting-labels-i-qqplot2-tp3657119p3677248.html
Sent from the R help mailing list archive at Nabble.com.



--
Brian S. Diggs, PhD
Senior Research Associate, Department of Surgery
Oregon Health & Science University

______________________________________________
R-help@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.

Reply via email to