Re: [R] grey colored lines and overwriting labels i qqplot2
On 7/25/2011 8:27 PM, Sigrid wrote: Thank you Brian. Sorry for being such a noob. I am not a programmer and just learning R by myself. This is was I typed, but ended up with a couple error messages. df-structure(list(year = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, + 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, + 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, + 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, + 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, + 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, + 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, + 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, + 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, + 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, + 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L), treatment = structure(c(1L, + 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, + 6L, 7L, 7L, 7L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, + 5L, 5L, 5L, 6L, 6L, 6L, 7L, 7L, 7L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, + 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 7L, 7L, 7L, 1L, 1L, + 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, + 7L, 7L, 7L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, + 5L, 5L, 6L, 6L, 6L, 7L, 7L, 7L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, + 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 7L, 7L, 7L, 1L, 1L, 2L, + 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 7L, 7L, + 7L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, + 6L, 6L, 6L, 7L, 7L, 7L), .Label = c(A, B, C, D, E, + F, G), class = factor), total = c(135L, 118L, 121L, 64L, + 53L, 49L, 178L, 123L, 128L, 127L, 62L, 129L, 126L, 99L, 183L, + 45L, 57L, 45L, 72L, 30L, 71L, 123L, 89L, 102L, 60L, 44L, 59L, + 124L, 145L, 126L, 103L, 67L, 97L, 66L, 76L, 108L, 36L, 48L, 41L, + 69L, 47L, 57L, 167L, 136L, 176L, 85L, 36L, 82L, 222L, 149L, 171L, + 145L, 122L, 192L, 136L, 164L, 154L, 46L, 57L, 57L, 70L, 55L, + 102L, 111L, 152L, 204L, 41L, 46L, 103L, 156L, 148L, 155L, 103L, + 124L, 176L, 111L, 142L, 187L, 43L, 52L, 75L, 64L, 91L, 78L, 196L, + 314L, 265L, 44L, 39L, 98L, 197L, 273L, 274L, 89L, 91L, 74L, 91L, + 112L, 98L, 140L, 90L, 121L, 120L, 161L, 83L, 230L, 266L, 282L, + 35L, 53L, 57L, 315L, 332L, 202L, 90L, 79L, 89L, 67L, 116L, 109L, + 44L, 68L, 75L, 29L, 52L, 52L, 253L, 203L, 87L, 105L, 234L, 152L, + 247L, 243L, 144L, 167L, 165L, 95L, 300L, 128L, 125L, 84L, 183L, + 88L, 153L, 185L, 175L, 226L, 216L, 118L, 118L, 94L, 224L, 259L, + 176L, 175L, 147L, 197L, 141L, 176L, 187L, 87L, 92L, 148L, 86L, + 139L, 122L), country = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, + 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, + 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, + 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, + 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, + 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, + 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, + 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, + 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, + 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, + 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L + ), .Label = c(high, low), class = factor)), .Names = c(year, + treatment, total, country), class = data.frame, row.names = c(NA, + -167L)) OK, here you have created a data.frame named df. It has four columns: year, treatment, total, and country. year is 1, 2, 3, or 4. treatment is a factor with values A, B, C, D, E, F, or G. total is a number (integer). country is a factor with values high or low. dput(lines) Error: unexpected '' in The at the beginning of this line represented the prompt; it was not supposed to be typed in. 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)) And this was the output of the dput command. If you want to recreate lines, you need: 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)) This creates a data frame named lines. it has 5 columns: Line
Re: [R] grey colored lines and overwriting labels i qqplot2
Thank you Brian. Sorry for being such a noob. I am not a programmer and just learning R by myself. This is was I typed, but ended up with a couple error messages. df -structure(list(year = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, + 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, + 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, + 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, + 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, + 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, + 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, + 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, + 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, + 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, + 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L), treatment = structure(c(1L, + 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, + 6L, 7L, 7L, 7L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, + 5L, 5L, 5L, 6L, 6L, 6L, 7L, 7L, 7L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, + 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 7L, 7L, 7L, 1L, 1L, + 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, + 7L, 7L, 7L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, + 5L, 5L, 6L, 6L, 6L, 7L, 7L, 7L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, + 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 7L, 7L, 7L, 1L, 1L, 2L, + 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 7L, 7L, + 7L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, + 6L, 6L, 6L, 7L, 7L, 7L), .Label = c(A, B, C, D, E, + F, G), class = factor), total = c(135L, 118L, 121L, 64L, + 53L, 49L, 178L, 123L, 128L, 127L, 62L, 129L, 126L, 99L, 183L, + 45L, 57L, 45L, 72L, 30L, 71L, 123L, 89L, 102L, 60L, 44L, 59L, + 124L, 145L, 126L, 103L, 67L, 97L, 66L, 76L, 108L, 36L, 48L, 41L, + 69L, 47L, 57L, 167L, 136L, 176L, 85L, 36L, 82L, 222L, 149L, 171L, + 145L, 122L, 192L, 136L, 164L, 154L, 46L, 57L, 57L, 70L, 55L, + 102L, 111L, 152L, 204L, 41L, 46L, 103L, 156L, 148L, 155L, 103L, + 124L, 176L, 111L, 142L, 187L, 43L, 52L, 75L, 64L, 91L, 78L, 196L, + 314L, 265L, 44L, 39L, 98L, 197L, 273L, 274L, 89L, 91L, 74L, 91L, + 112L, 98L, 140L, 90L, 121L, 120L, 161L, 83L, 230L, 266L, 282L, + 35L, 53L, 57L, 315L, 332L, 202L, 90L, 79L, 89L, 67L, 116L, 109L, + 44L, 68L, 75L, 29L, 52L, 52L, 253L, 203L, 87L, 105L, 234L, 152L, + 247L, 243L, 144L, 167L, 165L, 95L, 300L, 128L, 125L, 84L, 183L, + 88L, 153L, 185L, 175L, 226L, 216L, 118L, 118L, 94L, 224L, 259L, + 176L, 175L, 147L, 197L, 141L, 176L, 187L, 87L, 92L, 148L, 86L, + 139L, 122L), country = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, + 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, + 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, + 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, + 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, + 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, + 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, + 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, + 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, + 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, + 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L + ), .Label = c(high, low), class = factor)), .Names = c(year, + treatment, total, country), class = data.frame, row.names = c(NA, + -167L)) dput(lines) Error: unexpected '' in 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)) Line # country treatment Intercept Slope 1 1 Low A81.470 47.267 2 2 Low B31.809 20.234 3 3 Low C69.892 33.717 4 4High A67.024 47.267 5 5High B17.357 20.234 6 6High C 105.107 33.717 p=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) + +
Re: [R] grey colored lines and overwriting labels i qqplot2
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 TreatmentIntercept 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.10733.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 A81.470 47.267 2 2 Low B31.809 20.234 3 3 Low C69.892 33.717 4 4High A67.024 47.267 5 5High B17.357 20.234 6 6High 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.
Re: [R] grey colored lines and overwriting labels i qqplot2
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 TreatmentIntercept 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.10733.717 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()+ 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. __ 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.
Re: [R] grey colored lines and overwriting labels i qqplot2
Okay, seems like ddply is not the right method to add my model. That is okay, though. I already calculated the slopes and intercepts fore each for the treatments and country. How can I add those 14 lines? -- View this message in context: http://r.789695.n4.nabble.com/grey-colored-lines-and-overwriting-labels-i-qqplot2-tp3657119p3669823.html Sent from the R help mailing list archive at Nabble.com. __ 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.
Re: [R] grey colored lines and overwriting labels i qqplot2
Hi: What did you do and what do you mean by 'add[ing] those 14 lines'? A reproducible example would be helpful. I've used plyr successfully to get model coefficients before, so I'm interested in what you mean by 'ddply is not the right method to add my model.' Here's a toy reproducible example to counter your claim: library('plyr') set.seed(1036) df - data.frame(gp = rep(1:5, each = 10), x = 1:10, y = 1.5 + 2 * rep(1:10, 5) + rnorm(50)) # function to generate the model coefficients for a generic data frame lmfun - function(d) coef(lm(y ~ x, data = d)) # Apply the function to each sub-data frame associated with groups: ddply(df, .(gp), lmfun) gp (Intercept)x 1 1 1.2481481 2.011974 2 2 1.3125070 1.977223 3 3 0.5988811 2.212524 4 4 0.8575467 2.075925 5 5 2.1428869 1.903015 Internally, ddply() splits df into five sub-data frames corresponding to each level of gp. The function lmfun() is applied to each sub-data frame. Notice that the function argument is a data frame (observe that data = d inside lm()). It is often advantageous to run lm() by group, exporting the output to a list of lists (since the output from lm() is a list), from which plyr can use the ldply() function to pick off pieces of output from each group. I've done this several times before in this forum, so I'm not going to repeat it here. If you post what you tried that didn't work, perhaps I or someone else can get it to work for you. As mentioned above, reproducible code and data (with dput()) is ideal. Dennis On Fri, Jul 15, 2011 at 5:26 AM, Sigrid s.stene...@gmail.com wrote: Okay, seems like ddply is not the right method to add my model. That is okay, though. I already calculated the slopes and intercepts fore each for the treatments and country. How can I add those 14 lines? -- View this message in context: http://r.789695.n4.nabble.com/grey-colored-lines-and-overwriting-labels-i-qqplot2-tp3657119p3669823.html Sent from the R help mailing list archive at Nabble.com. __ 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. __ 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.
Re: [R] grey colored lines and overwriting labels i qqplot2
You should only have one scale_ call for each scale type. Here, you have three scale_colour_ calls, the first selecting a grey scale, the second defining a single break with its label (and thus implicitly subsetting on that single break value), and a second which defines a different break/label/subset. Only the last one has any effect. Just to clarify: breaks/labels control the appearance of the legend/axis, limits modify what data is shown on the plot. Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/ __ 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.
Re: [R] grey colored lines and overwriting labels i qqplot2
Great! Thank you, Brian. To answer your question about intercept and slopes, I got them from a covariance analysis that I had already conducted. It seems like I can not use the regressions command for the model that I used to get the intercepts and slopes. I guess 2 factors are the maximum. + ddply(test, c(country,treatment), + function(x) { + coef(lm(total~ treatment+ year+ country + treatment:year, x)) + }) Error in `contrasts-`(`*tmp*`, value = contr.treatment) : contrasts can be applied only to factors with 2 or more levels Any way to get around this? How about getting back to the abline command? Thank you. -- View this message in context: http://r.789695.n4.nabble.com/grey-colored-lines-and-overwriting-labels-i-qqplot2-tp3657119p3666473.html Sent from the R help mailing list archive at Nabble.com. __ 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.
Re: [R] grey colored lines and overwriting labels i qqplot2
Hi Sigrid, On Wed, Jul 13, 2011 at 9:47 PM, Sigrid s.stene...@gmail.com wrote: Great! Thank you, Brian. To answer your question about intercept and slopes, I got them from a covariance analysis that I had already conducted. It seems like I can not use the regressions command for the model that I used to get the intercepts and slopes. I guess 2 factors are the maximum. Two _levels_ of a factor is the _minimum_ ! Otherwise it is a constant, not a variable. + ddply(test, c(country,treatment), + function(x) { + coef(lm(total~ treatment+ year+ country + treatment:year, x)) + }) Error in `contrasts-`(`*tmp*`, value = contr.treatment) : contrasts can be applied only to factors with 2 or more levels Any way to get around this? How about getting back to the abline command? ddply splits the data in the first argument by the second argument. So you can read your first line as for every level defined by the combination of county and treatment, extract the linear coefficients of total regressed onto county, year, treatment, and the treatment X year interaction. The problem with this is that each subset only has one level of country and one level of treatment (see the first part of the description above). So these are now constants, and you can't treat constants as variables in a linear model. Thank you. -- View this message in context: http://r.789695.n4.nabble.com/grey-colored-lines-and-overwriting-labels-i-qqplot2-tp3657119p3666473.html Sent from the R help mailing list archive at Nabble.com. __ 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. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ 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.
Re: [R] grey colored lines and overwriting labels i qqplot2
Merging two posts (data and questions); see inline below. On 7/11/2011 7:55 PM, Sigrid wrote: Thank you, Dennis. This is my regenerated dput codes. They should be correct as I closed off R and re-ran them based on the dput output. NB, this is the test dataset used later structure(list(year = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L), treatment = structure(c(1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 7L, 7L, 7L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 7L, 7L, 7L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 7L, 7L, 7L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 7L, 7L, 7L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 7L, 7L, 7L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 7L, 7L, 7L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 7L, 7L, 7L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 7L, 7L, 7L), .Label = c(A, B, C, D, E, F, G), class = factor), total = c(135L, 118L, 121L, 64L, 53L, 49L, 178L, 123L, 128L, 127L, 62L, 129L, 126L, 99L, 183L, 45L, 57L, 45L, 72L, 30L, 71L, 123L, 89L, 102L, 60L, 44L, 59L, 124L, 145L, 126L, 103L, 67L, 97L, 66L, 76L, 108L, 36L, 48L, 41L, 69L, 47L, 57L, 167L, 136L, 176L, 85L, 36L, 82L, 222L, 149L, 171L, 145L, 122L, 192L, 136L, 164L, 154L, 46L, 57L, 57L, 70L, 55L, 102L, 111L, 152L, 204L, 41L, 46L, 103L, 156L, 148L, 155L, 103L, 124L, 176L, 111L, 142L, 187L, 43L, 52L, 75L, 64L, 91L, 78L, 196L, 314L, 265L, 44L, 39L, 98L, 197L, 273L, 274L, 89L, 91L, 74L, 91L, 112L, 98L, 140L, 90L, 121L, 120L, 161L, 83L, 230L, 266L, 282L, 35L, 53L, 57L, 315L, 332L, 202L, 90L, 79L, 89L, 67L, 116L, 109L, 44L, 68L, 75L, 29L, 52L, 52L, 253L, 203L, 87L, 105L, 234L, 152L, 247L, 243L, 144L, 167L, 165L, 95L, 300L, 128L, 125L, 84L, 183L, 88L, 153L, 185L, 175L, 226L, 216L, 118L, 118L, 94L, 224L, 259L, 176L, 175L, 147L, 197L, 141L, 176L, 187L, 87L, 92L, 148L, 86L, 139L, 122L), country = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L ), .Label = c(high, low), class = factor)), .Names = c(year, treatment, total, country), class = data.frame, row.names = c(NA, -167L)) I hope be useful for you when giving me a hand with my difficulties. On 7/9/2011 8:24 PM, Sigrid wrote: I created this graph in ggplot and added ablines to the different facets by specifying with subset commands. As you might see, there are still a few issues. 1.) I would like to have the diamonds in a grey scale instead of colors. I accomplished this (see graph 2) until I overwrote the label title for the treatments and the colors came back (graph 1). I used these two commands: p=ggplot(data = test, aes(x = YEAR, y = TOTAL, colour = TREATMENT)) + geom_point() + facet_wrap(~country)+scale_colour_grey()+ scale_y_continuous(number of votes)+ scale_x_continuous(Years)+ scale_x_continuous(breaks=1:4) + scale_colour_hue(breaks='A', labels='label A')+ scale_colour_hue(breaks='B', labels='label B') How can I keep the grey scale, but avoid changing back to colors when using the scale_colour_hue command? You should only have one scale_ call for each scale type. Here, you have three scale_colour_ calls, the first selecting a grey scale, the second defining a single break with its label (and thus implicitly subsetting on that single break value), and a second which defines a different break/label/subset. Only the last one has any effect. http://r.789695.n4.nabble.com/file/n3657119/color_graph.gif 2.) Furthermore, only one of the overwritten labels of the treatments came up, despite putting in two commands (graph 1). What could have happened here? p +
Re: [R] grey colored lines and overwriting labels i qqplot2
Thank you, Dennis. This is my regenerated dput codes. They should be correct as I closed off R and re-ran them based on the dput output. structure(list(year = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L), treatment = structure(c(1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 7L, 7L, 7L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 7L, 7L, 7L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 7L, 7L, 7L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 7L, 7L, 7L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 7L, 7L, 7L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 7L, 7L, 7L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 7L, 7L, 7L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 7L, 7L, 7L), .Label = c(A, B, C, D, E, F, G), class = factor), total = c(135L, 118L, 121L, 64L, 53L, 49L, 178L, 123L, 128L, 127L, 62L, 129L, 126L, 99L, 183L, 45L, 57L, 45L, 72L, 30L, 71L, 123L, 89L, 102L, 60L, 44L, 59L, 124L, 145L, 126L, 103L, 67L, 97L, 66L, 76L, 108L, 36L, 48L, 41L, 69L, 47L, 57L, 167L, 136L, 176L, 85L, 36L, 82L, 222L, 149L, 171L, 145L, 122L, 192L, 136L, 164L, 154L, 46L, 57L, 57L, 70L, 55L, 102L, 111L, 152L, 204L, 41L, 46L, 103L, 156L, 148L, 155L, 103L, 124L, 176L, 111L, 142L, 187L, 43L, 52L, 75L, 64L, 91L, 78L, 196L, 314L, 265L, 44L, 39L, 98L, 197L, 273L, 274L, 89L, 91L, 74L, 91L, 112L, 98L, 140L, 90L, 121L, 120L, 161L, 83L, 230L, 266L, 282L, 35L, 53L, 57L, 315L, 332L, 202L, 90L, 79L, 89L, 67L, 116L, 109L, 44L, 68L, 75L, 29L, 52L, 52L, 253L, 203L, 87L, 105L, 234L, 152L, 247L, 243L, 144L, 167L, 165L, 95L, 300L, 128L, 125L, 84L, 183L, 88L, 153L, 185L, 175L, 226L, 216L, 118L, 118L, 94L, 224L, 259L, 176L, 175L, 147L, 197L, 141L, 176L, 187L, 87L, 92L, 148L, 86L, 139L, 122L), country = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L ), .Label = c(high, low), class = factor)), .Names = c(year, treatment, total, country), class = data.frame, row.names = c(NA, -167L)) I hope be useful for you when giving me a hand with my difficulties. -- View this message in context: http://r.789695.n4.nabble.com/grey-colored-lines-and-overwriting-labels-i-qqplot2-tp3657119p3661351.html Sent from the R help mailing list archive at Nabble.com. __ 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.
Re: [R] grey colored lines and overwriting labels i qqplot2
Hi: I didn't save the original question, but I seem to recall it had something to do with overlapping labels. I don't know if this is exactly what you had in mind, but here's one approach. I named your data frame df below. library(ggplot2) ggplot(df, aes(x = year, y = total)) + geom_point() + geom_smooth() + facet_grid(country ~ treatment) + scale_x_continuous(breaks = 1:4, labels = 1L:4L) The L's in the label mean that integer values are meant to be printed rather than floating point numbers. If you have a larger set of x values whose labels overlap, you can set breaks manually inside scale_x_continuous(). (Side note: Using geom_smooth() generates a bunch of warnings that have to do with endpoint issues. In this case, they're fairly benign.) HTH, Dennis On Mon, Jul 11, 2011 at 7:55 PM, Sigrid s.stene...@gmail.com wrote: Thank you, Dennis. This is my regenerated dput codes. They should be correct as I closed off R and re-ran them based on the dput output. structure(list(year = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L), treatment = structure(c(1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 7L, 7L, 7L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 7L, 7L, 7L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 7L, 7L, 7L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 7L, 7L, 7L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 7L, 7L, 7L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 7L, 7L, 7L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 7L, 7L, 7L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 7L, 7L, 7L), .Label = c(A, B, C, D, E, F, G), class = factor), total = c(135L, 118L, 121L, 64L, 53L, 49L, 178L, 123L, 128L, 127L, 62L, 129L, 126L, 99L, 183L, 45L, 57L, 45L, 72L, 30L, 71L, 123L, 89L, 102L, 60L, 44L, 59L, 124L, 145L, 126L, 103L, 67L, 97L, 66L, 76L, 108L, 36L, 48L, 41L, 69L, 47L, 57L, 167L, 136L, 176L, 85L, 36L, 82L, 222L, 149L, 171L, 145L, 122L, 192L, 136L, 164L, 154L, 46L, 57L, 57L, 70L, 55L, 102L, 111L, 152L, 204L, 41L, 46L, 103L, 156L, 148L, 155L, 103L, 124L, 176L, 111L, 142L, 187L, 43L, 52L, 75L, 64L, 91L, 78L, 196L, 314L, 265L, 44L, 39L, 98L, 197L, 273L, 274L, 89L, 91L, 74L, 91L, 112L, 98L, 140L, 90L, 121L, 120L, 161L, 83L, 230L, 266L, 282L, 35L, 53L, 57L, 315L, 332L, 202L, 90L, 79L, 89L, 67L, 116L, 109L, 44L, 68L, 75L, 29L, 52L, 52L, 253L, 203L, 87L, 105L, 234L, 152L, 247L, 243L, 144L, 167L, 165L, 95L, 300L, 128L, 125L, 84L, 183L, 88L, 153L, 185L, 175L, 226L, 216L, 118L, 118L, 94L, 224L, 259L, 176L, 175L, 147L, 197L, 141L, 176L, 187L, 87L, 92L, 148L, 86L, 139L, 122L), country = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L ), .Label = c(high, low), class = factor)), .Names = c(year, treatment, total, country), class = data.frame, row.names = c(NA, -167L)) I hope be useful for you when giving me a hand with my difficulties. -- View this message in context: http://r.789695.n4.nabble.com/grey-colored-lines-and-overwriting-labels-i-qqplot2-tp3657119p3661351.html Sent from the R help mailing list archive at Nabble.com. __ 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. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide
Re: [R] grey colored lines and overwriting labels i qqplot2
Thank you, Ista, for your quick response and tip. I would love to make a reproducible example and was not aware of the dput codes as I am a new user. Is there anywhere I can read up on how to use dput? Sigrid -- View this message in context: http://r.789695.n4.nabble.com/grey-colored-lines-and-overwriting-labels-i-qqplot2-tp3657119p3657200.html Sent from the R help mailing list archive at Nabble.com. __ 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.
Re: [R] grey colored lines and overwriting labels i qqplot2
Hi: Here's a simple example: df - data.frame(x = 1:10, y = rnorm(10)) dput(df) structure(list(x = 1:10, y = c(-1.55669581922794, -0.6086844726417, -0.414989571570644, -0.202690819994734, -0.421436945159872, 0.00216009424665418, -0.193955384660702, -0.764966890023485, -0.740871219664316, -0.0193951410439701 )), .Names = c(x, y), row.names = c(NA, -10L), class = data.frame) ### Other end: df - copy and paste the lines below dput str(df) It should match this: str(df) 'data.frame': 10 obs. of 2 variables: $ x: int 1 2 3 4 5 6 7 8 9 10 $ y: num -1.557 -0.609 -0.415 -0.203 -0.421 ... The advantages of dput() form are that: (i) the structure of the (data) object in question is preserved; (ii) it can be copied and pasted directly into one's R session from an e-mail; (iii) it is text-based and therefore portable across platforms (e.g., Mac, Linux, PC). Sending data in dput() form assures a potential helpeR that the structure of the data will be exactly the same in his/her R session as it is in yours. This is not always the case if you copy and paste a portion of data from the console to an e-mail; for example, integer variables on the sender's end may end up read as numeric on the other end, character variables may be read in as factors (most notoriously, dates), etc. These infelicities can matter and cause confusion and/or frustration on both ends. dput() is the safest way to portably transfer data in R. The other option, which is equally safe, is to send the code to generate a toy data set that is replicable on the other end, preferably with a prefatory set.seed() statement, something like set.seed(1358) df - data.frame(x = 1:10, y = rnorm(10)) head(df, 4) x y 1 1 0.50587229 2 2 2.34666229 3 3 -0.05024859 4 4 1.40323363 With a stated set.seed(), the y values should be the same on both ends. I can't speak for anyone else, but I decided a while ago that if a poster didn't show enough courtesy to provide a reproducible example, I wasn't going to invest time or energy responding to the question unless the answer was obvious or I had a personal interest in the question at hand. There's a reason why the Posting Guide exists. When you follow its guidelines, there is ample evidence to show that: (a) more people are willing to look at the problem and provide useful feedback; (b) the answers will usually arrive quickly; (c) you will often end up with multiple solutions to the problem, or a diagnosis of why something didn't work. This is a very high volume list - it's not unusual for 100+ messages to pass back and forth in a single day. With that amount of competition for the time and attention of potential helpeRs, those who learn how to post readily answerable questions generally get more attention than those who do not. Thank you for showing enough consideration to want to learn how to post in a manner that benefits both you and potential helpeRs. I sincerely hope this is helpful to you (and perhaps others in a similar position). Dennis On Sat, Jul 9, 2011 at 10:36 PM, Sigrid s.stene...@gmail.com wrote: Thank you, Ista, for your quick response and tip. I would love to make a reproducible example and was not aware of the dput codes as I am a new user. Is there anywhere I can read up on how to use dput? Sigrid -- View this message in context: http://r.789695.n4.nabble.com/grey-colored-lines-and-overwriting-labels-i-qqplot2-tp3657119p3657200.html Sent from the R help mailing list archive at Nabble.com. __ 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. __ 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.
Re: [R] grey colored lines and overwriting labels i qqplot2
Please give a reproducible example. Since we do not have the test data we cannot run your code. One way you might do this is by posting the output of dput(test) Best, Ista On Sat, Jul 9, 2011 at 11:24 PM, Sigrid s.stene...@gmail.com wrote: I created this graph in ggplot and added ablines to the different facets by specifying with subset commands. As you might see, there are still a few issues. 1.) I would like to have the diamonds in a grey scale instead of colors. I accomplished this (see graph 2) until I overwrote the label title for the treatments and the colors came back (graph 1). I used these two commands: p=ggplot(data = test, aes(x = YEAR, y = TOTAL, colour = TREATMENT)) + geom_point() + facet_wrap(~country)+scale_colour_grey()+ scale_y_continuous(number of votes)+ scale_x_continuous(Years)+ scale_x_continuous(breaks=1:4) + scale_colour_hue(breaks='A', labels='label A')+ scale_colour_hue(breaks='B', labels='label B') How can I keep the grey scale, but avoid changing back to colors when using the scale_colour_hue command? http://r.789695.n4.nabble.com/file/n3657119/color_graph.gif 2.) Furthermore, only one of the overwritten labels of the treatments came up, despite putting in two commands (graph 1). What could have happened here? p + scale_colour_hue(breaks='A', labels='label A')+ scale_colour_hue(breaks='B', labels='label B') 3.) I would like to add the lines so it matches the default grey scale (graph 2), but I do not know the name of the different shades in the grey scale. I added the lines in the following way: p + geom_abline(intercept = 81.476, slope=47.267, colour = green, size = 1, subset = .(country == 'low'))+ geom_abline(intercept = 31.809, slope=20.234, colour = blue, size = 1, subset = .(country == 'low')) +. http://r.789695.n4.nabble.com/file/n3657119/color_graph_2.gif And now I would like to add lines fitting accordingly with the grey scale. Where can I find out the names of the grey tones? 4.) I would like to add different shapes. However, when I type p+ geom_point(aes(shape = factor(TREATMENT))) + scale_shape(solid = FALSE) I get this error message: Error: scale_shape_discrete can deal with a maximum of 6 discrete values, but you have 7. See ?scale_manual for a possible alternative. I did not find anything useful looking at the scale_manual pages. Any tips on how to add another symbol? 5. ) Finally, how can I remove the grey background in the graph? Thank you for all input! -- View this message in context: http://r.789695.n4.nabble.com/grey-colored-lines-and-overwriting-labels-i-qqplot2-tp3657119p3657119.html Sent from the R help mailing list archive at Nabble.com. __ 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. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ 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.