Gen
2007-Aug-30 04:50 UTC
[R] customizing the color and point shape for each line drawn using lattice's xyplot
Description of what I am trying to do: I am using the xyplot code below to plot the variable ?MeanBxg? against the variable ?PercentVarExplained? for all 9 possible combinations of variables ?bdg? and ?bdx?. Within each of these 9 scenarios I am plotting a separate line for each of up to 9 different methods that I used to estimate the variable MeanBxg. These methods are identified by the numeric variable called ?Method.? Giving me one plot with 9 figures and each of the figures contains 9 lines. My problem arises because I would like to repeat the creation of this plot 8 times, in each instance only a subset (eg 6) of the 9 methods are used (a different subset each time). What I can?t figure out: I would like to learn how to specify the exact line color that corresponds to each method such that Method==1 will always be represented by the same color (in every plot that it appears in). Where two methods that I used were of the same family of methods (say method==1 and method==2 made the same assumptions about the data) I would like to, if possible, represent the two methods using the same color and distinguish them by the symbol used to represent points on the line. My code as it currently stands: xyplot(MeanBxg ~ PercentVarExplained | bdg.f * bdx.f, data=common, groups=common$Method.f, type="l", subset= Method!=4, auto.key=T) As the code is, the default colors assigned are repeated causing different methods to be represented by the same color with no way to distinguish them (I have not succeeded in plotting lines and points simultaneously). Side question: When I subset the data to particular methods, is there a way to remove the excluded methods from the key as well? (in my code ?Method? is a numeric variable, and ?Method.f? corresponds to the lengthy descriptions of each method for the purpose of the key) Thank you very much for your help. Genevieve -- View this message in context: http://www.nabble.com/customizing-the-color-and-point-shape-for-each-line-drawn-using-lattice%27s-xyplot-tf4351934.html#a12400517 Sent from the R help mailing list archive at Nabble.com.
Ross Darnell
2007-Aug-30 05:56 UTC
[R] customizing the color and point shape for each line drawn using lattice's xyplot
Does this help common.without.Method4 <- subset(common, Method!=4) xyplot(MeanBxg ~ PercentVarExplained | bdg.f * bdx.f, data=common.without.Method4, groups=Method.f, type="l", auto.key=T) Ross Darnell -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Gen Sent: Thursday, 30 August 2007 2:51 PM To: r-help at stat.math.ethz.ch Subject: [R] customizing the color and point shape for each line drawn using lattice's xyplot Description of what I am trying to do: I am using the xyplot code below to plot the variable "MeanBxg" against the variable "PercentVarExplained" for all 9 possible combinations of variables "bdg" and "bdx". Within each of these 9 scenarios I am plotting a separate line for each of up to 9 different methods that I used to estimate the variable MeanBxg. These methods are identified by the numeric variable called "Method." Giving me one plot with 9 figures and each of the figures contains 9 lines. My problem arises because I would like to repeat the creation of this plot 8 times, in each instance only a subset (eg 6) of the 9 methods are used (a different subset each time). What I can't figure out: I would like to learn how to specify the exact line color that corresponds to each method such that Method==1 will always be represented by the same color (in every plot that it appears in). Where two methods that I used were of the same family of methods (say method==1 and method==2 made the same assumptions about the data) I would like to, if possible, represent the two methods using the same color and distinguish them by the symbol used to represent points on the line. My code as it currently stands: xyplot(MeanBxg ~ PercentVarExplained | bdg.f * bdx.f, data=common, groups=common$Method.f, type="l", subset= Method!=4, auto.key=T) As the code is, the default colors assigned are repeated causing different methods to be represented by the same color with no way to distinguish them (I have not succeeded in plotting lines and points simultaneously). Side question: When I subset the data to particular methods, is there a way to remove the excluded methods from the key as well? (in my code "Method" is a numeric variable, and "Method.f" corresponds to the lengthy descriptions of each method for the purpose of the key) Thank you very much for your help. Genevieve -- View this message in context: http://www.nabble.com/customizing-the-color-and-point-shape-for-each-lin e-drawn-using-lattice%27s-xyplot-tf4351934.html#a12400517 Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help at stat.math.ethz.ch 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.
deepayan.sarkar at gmail.com
2007-Aug-30 23:32 UTC
[R] customizing the color and point shape for each line drawn using lattice's xyplot
On 8/29/07, Gen <gingerlygen at gmail.com> wrote:> > Description of what I am trying to do: > I am using the xyplot code below to plot the variable "MeanBxg" against the > variable "PercentVarExplained" for all 9 possible combinations of variables > "bdg" and "bdx". Within each of these 9 scenarios I am plotting a separate > line for each of up to 9 different methods that I used to estimate the > variable MeanBxg. These methods are identified by the numeric variable > called "Method." Giving me one plot with 9 figures and each of the figures > contains 9 lines. > > My problem arises because I would like to repeat the creation of this plot 8 > times, in each instance only a subset (eg 6) of the 9 methods are used (a > different subset each time). > > What I can't figure out: > I would like to learn how to specify the exact line color that corresponds > to each method such that Method==1 will always be represented by the same > color (in every plot that it appears in). Where two methods that I used > were of the same family of methods (say method==1 and method==2 made the > same assumptions about the data) I would like to, if possible, represent > the two methods using the same color and distinguish them by the symbol used > to represent points on the line. > > My code as it currently stands: > xyplot(MeanBxg ~ PercentVarExplained | bdg.f * bdx.f, data=common, > groups=common$Method.f, type="l", subset= Method!=4, auto.key=T) > > As the code is, the default colors assigned are repeated causing different > methods to be represented by the same color with no way to distinguish them > (I have not succeeded in plotting lines and points simultaneously). > > Side question: When I subset the data to particular methods, is there a way > to remove the excluded methods from the key as well? (in my code "Method" is > a numeric variable, and "Method.f" corresponds to the lengthy descriptions > of each method for the purpose of the key)It's not clear what you actually want, and you haven't given us a reproducible example. Some general comments: 1. try type = "o" for both points and lines, and auto.key list(points = TRUE, lines = TRUE) if you meant this for the legend. 2. The number of distinct colors is 7 by default, after which they get recycled. You can set the colors by changing the superpose.line$col setting (see ?trellis.par.set and the entry for 'par.settings' in ?xyplot) 3. The number of colors used is related to the number of levels of 'groups'. If you want fewer colors (or not have unused colors in the legend), you need to make sure your 'groups' variable has a suitably reduced set of levels. There is no cute way to do this. The long way is subdata <- subset(common, Method != 4) subdata$Method.f <- subdata$Method.f[, drop = TRUE] -Deepayan