[R] xyplot: legend title + legend on 1 line
Does anybody know how in xyplot to put the legend title on one line with the legend? I can get the legend on one line with columns=... but the title is always on top. I tried a custom key with key=... and text=... but I can't put the title text in front of the plotting symbol. I am looking for the following layout of the legend, on one line: Legend Title: + plot symbol1 + legend text1 + plot symbol2 + legend text2 + ... Thanks. Rene -- View this message in context: http://www.nabble.com/xyplot%3A-legend-title-%2B-legend-on-1-line-tf2829327.html#a7898800 Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
[R] xyplot: logarithmic y-axis
This should be simple but I am struggling. I like to easily switch in xyplot between a linear or logarithmic y-axis by setting a logical flag logY to False or True. This switch changes the scales argument of xyplot. I found out that the original two-dimentional data (Conc vs Time in my case) are converted to log10(Conc) if log=TRUE in scales, but it appears that functions like panel.curve need to provide the y values in log10 form (if there is an automatic method, I would like to know). I therefore like to pass on the value logY to my custom panel.curve function. How do I do that? I think that the value of logY should go into xyplot that should pass it on to the panel function and then to the panel.curve function. Thanks, -Rene logY=TRUE # Custom panel.curve function myCurve -function(x, log) { f - ... # calculate curve here if (log==TRUE) f - log10(f) return(f) } xyplot(Conc ~ Time | Subj, groups=Dose, data = mydata, as.table=TRUE, scales=list(y=list(log=logY)), panel = function(...) { panel.abline(h=c(0, 50, 100, 150, 200, 250) , v=c(0,24,48,72,96), col.line=gray) panel.xyplot(...) panel.curve(myCurve, from=0, to=96, n=300)) } ) -- View this message in context: http://www.nabble.com/xyplot%3A-logarithmic-y-axis-tf2829755.html#a7900202 Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] xyplot: logarithmic y-axis
Please take no offence since none was intended. What I meant is that it should be simple for me to know how to do this but it isn't because of my inexperience. I think that the lattice package is great. However, how can I pass on my own varaibles through xyplot? Thanks, -Rene Deepayan Sarkar wrote: On 12/15/06, RMan54 [EMAIL PROTECTED] wrote: This should be simple but I am struggling. I like to easily switch in xyplot between a linear or logarithmic y-axis by setting a logical flag logY to False or True. This switch changes the scales argument of xyplot. I found out that the original two-dimentional data (Conc vs Time in my case) are converted to log10(Conc) if log=TRUE in scales, but it appears that functions like panel.curve need to provide the y values in log10 form (if there is an automatic method, I would like to know). I therefore like to pass on the value logY to my custom panel.curve function. How do I do that? I think that the value of logY should go into xyplot that should pass it on to the panel function and then to the panel.curve function. It probably should, but doesn't. -Deepayan __ R-help@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. -- View this message in context: http://www.nabble.com/xyplot%3A-logarithmic-y-axis-tf2829755.html#a7900634 Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] xyplot: logarithmic y-axis
I added logY as the last argument to xyplot and in my curve function. I got the following error message: Error in myCurve(x) : argument log is missing, with no default myCurve -function(x, log) { f - ... # calculate curve here if (log==T) f - log10(f) return(f) } logY=T xyplot(Conc ~ Time | Subj, groups=Dose, data = mydata, scales=list(x=list(at=seq(0,96,24)), y=list(log=logY)), panel = function(...) { panel.abline(h=c(0, 50, 100, 150, 200, 250) , v=c(0,24,48,72,96), col.line=gray) panel.xyplot(...) panel.curve(myCurve, from=0, to=96, n=300, ..., log=logY) }, logY ) Deepayan Sarkar wrote: On 12/15/06, RMan54 [EMAIL PROTECTED] wrote: Please take no offence since none was intended. What I meant is that it should be simple for me to know how to do this but it isn't because of my inexperience. I think that the lattice package is great. I didn't mean to suggest that I was offended. I only agreed with you that it would be nice if there were a way of knowing inside the panel function whether a log scale is being used, and informing you that there isn't. However, how can I pass on my own varaibles through xyplot? Any arguments not recognized by xyplot will be passed to the panel function. -Deepayan Thanks, -Rene Deepayan Sarkar wrote: On 12/15/06, RMan54 [EMAIL PROTECTED] wrote: This should be simple but I am struggling. I like to easily switch in xyplot between a linear or logarithmic y-axis by setting a logical flag logY to False or True. This switch changes the scales argument of xyplot. I found out that the original two-dimentional data (Conc vs Time in my case) are converted to log10(Conc) if log=TRUE in scales, but it appears that functions like panel.curve need to provide the y values in log10 form (if there is an automatic method, I would like to know). I therefore like to pass on the value logY to my custom panel.curve function. How do I do that? I think that the value of logY should go into xyplot that should pass it on to the panel function and then to the panel.curve function. It probably should, but doesn't. -Deepayan __ R-help@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. -- View this message in context: http://www.nabble.com/xyplot%3A-logarithmic-y-axis-tf2829755.html#a7901073 Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] xyplot: discrete points + continuous curve per panel
Great. I will be trying to use panel.curve and pass a custom curve function as first argument (called test() below). I can use which. packet to get access to the panel number to produce the correct curve for each panel but what I really need is the active Subj (actSubj) for each panel. Not sure but it seems that Subj is passed on to the functions but in replicates. Here is what I came up with to eliminate the replication and to calculate activeSubj for each panel in test(). Is this the correct way? How can I pass on Subj and Dose directly to test()? Thanks, Rene test -function(x) { activeSubj - unique(Subj)[which.packet()] x # returns y=x for testing only } xyplot(Conc ~ Time | Subj, groups=Dose, data = mydata, as.table=T, panel = function(x,y) { panel.xyplot(x,y) panel.curve(test, n=2) } ) Deepayan Sarkar wrote: On 12/13/06, RMan54 [EMAIL PROTECTED] wrote: I have a number of x, y observations (Time, Conc) for a number of Subjects (with subject number Subj) and Doses. I can plot the individual points with xyplot fine: xyplot(Conc ~ Time | Subj, Groups=Dose, data=myData, panel = function(x,y) { panel.xyplot(x, y) panel.superpose(???) # Needs more here } ) I also like to plot on each panel (there is one Subj per panel) a continuous curve with predictions that I can calculate from a rather complicated function: myPred - (time, subj, dose) { returns predicted value of Conc for a given time, subj and dose } The predicted curves are different for each panel. How do I plot the predictions? I have tried to add panel.superinpose in the xyplot portion but can't link to the myPred function. I also know about panel.curve but couldn't make it work. My attempt is to calculate the predictions on the fly. Is this possible? Or do I need to calculate all predictions first and put the results in a data frame. Depends on how much work you are willing to do. There is no reason for panel.curve to not work, provided you give it a curve to plot. This is normally done in the form of a vectorized function of one variable, which will be called with a vector of values spanning the x-axis of your plot. It is your responsibility to construct such a function inside each panel (presumably it would involve your myPred function). The easy way, that generally works well for longitudinal data (with increasing x values within a panel), is to add a column of predicted values to your data frame. For most model fitting routines in R, the paradigm is: fm - some.model(y ~ whatever, data = mydata, ...) mydata$fit - fitted(fm) xyplot(y + fit ~ whatever, type = list(p, l), distribute.type = TRUE) A real example being: library(lme4) data(Oxboys, package = nlme) Oxboys$fit - fitted(lmer(height ~ age + (1|Subject), data = Oxboys)) xyplot(height + fit ~ age | Subject, Oxboys, type = c(p, l), distribute.type = TRUE, aspect = xy) Things will be more complicated if you already have a grouping variable (the solution is to pass down the vector of fitted values to the panel function and use 'subscripts' to retrieve the ones that belong in the panel). -Deepayan __ R-help@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. -- View this message in context: http://www.nabble.com/xyplot%3A-discrete-points-%2B-continuous-curve-per-panel-tf2818931.html#a7886826 Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
[R] Reverse order of grouping factor in grouppedData
I created the following groupedData object (nlme library): gd - groupedData(Conc ~ Time | Subj, order.groups=T, FUN = myf, data=mydata) The idea of the myf function is to reverse the order of the grouping factor Subj (or better, reorder from largest to smallest). In the mydata data set, Subj is an integer that gets converted into a factor in the groupedData object. Does anyone knows how to write this function myf? It may be even impossible to do it this way because the function is applied on the dependent variable Conc (default in the package is mean), while I need to apply my stuff on the factor Subj. The lattice plot routines underneath the nlme library (like xyplot) unfortunately start plotting the panels on the bottom of the page and up. In order to have the order in a logical fashion (smallest to highest subj number starting on top of the page and down), I need to reorder in the groupedData object. -- View this message in context: http://www.nabble.com/Reverse-order-of-grouping-factor-in-grouppedData-tf2817711.html#a7864653 Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
[R] xyplot: discrete points + continuous curve per panel
I have a number of x, y observations (Time, Conc) for a number of Subjects (with subject number Subj) and Doses. I can plot the individual points with xyplot fine: xyplot(Conc ~ Time | Subj, Groups=Dose, data=myData, panel = function(x,y) { panel.xyplot(x, y) panel.superpose(???) # Needs more here } ) I also like to plot on each panel (there is one Subj per panel) a continuous curve with predictions that I can calculate from a rather complicated function: myPred - (time, subj, dose) { returns predicted value of Conc for a given time, subj and dose } The predicted curves are different for each panel. How do I plot the predictions? I have tried to add panel.superinpose in the xyplot portion but can't link to the myPred function. I also know about panel.curve but couldn't make it work. My attempt is to calculate the predictions on the fly. Is this possible? Or do I need to calculate all predictions first and put the results in a data frame. Thanks for any help, Rene -- View this message in context: http://www.nabble.com/xyplot%3A-discrete-points-%2B-continuous-curve-per-panel-tf2818931.html#a7867892 Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
[R] Numbers with correct significant digits
This, for example: v - c(9.6996, 99.99) formatC(v, digits=3, format=g) shows: 9.7 100 This is scientifically incorrect for the first number in the sense that I like to show all 3 significant digits, including trailing zero's. Is there a way that the first number would show as 9.70? By the way, can't use format() since it applies the same numbers of digits after the decimal point for all numbers in the vector. Thanks, Rene -- View this message in context: http://www.nabble.com/Numbers-with-correct-significant-digits-tf2657246.html#a7412042 Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] Numbers with correct significant digits
I think that I answered my own question. Since formatC is an implementation of the C-style formatting, I thought that a # as flag could work (for g and G conversions, trailing zeros are not removed from the result as they would otherwise be). Although not in the online help, this worked in R as follows: v - c(9.6996, 99.99) formatC(v, digits=3, format=g, flag=#) result: 9.70 100. The only small annoyance is that the decimal point is always shown. RMan54 wrote: This, for example: v - c(9.6996, 99.99) formatC(v, digits=3, format=g) shows: 9.7 100 This is scientifically incorrect for the first number in the sense that I like to show all 3 significant digits, including trailing zero's. Is there a way that the first number would show as 9.70? By the way, can't use format() since it applies the same numbers of digits after the decimal point for all numbers in the vector. Thanks, Rene -- View this message in context: http://www.nabble.com/Numbers-with-correct-significant-digits-tf2657246.html#a7412389 Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] Numbers with correct significant digits
Yes, you can always tweak one number but it may mess up the others. That's why my example included two numbers. When you use sprintf this way: v - c(9.6996, 99.99) sprintf(%.2f, v) you get: 9.70 99.99 Now I have 4 significant digits for the 2nd number! The .2 in the format string always gives you 2 digits after the decimal point but not always 3 significant digits. Rene Andrew Robinson-6 wrote: I have found that sprintf gets this right, although the syntax of the command itself is a little less clear. sprintf(%.2f, 9.6996) [1] 9.70 I hope that this helps, Andrew On Fri, Nov 17, 2006 at 02:14:58PM -0800, RMan54 wrote: This, for example: v - c(9.6996, 99.99) formatC(v, digits=3, format=g) shows: 9.7 100 This is scientifically incorrect for the first number in the sense that I like to show all 3 significant digits, including trailing zero's. Is there a way that the first number would show as 9.70? By the way, can't use format() since it applies the same numbers of digits after the decimal point for all numbers in the vector. Thanks, Rene -- View this message in context: http://www.nabble.com/Numbers-with-correct-significant-digits-tf2657246.html#a7412042 Sent from the R help mailing list archive at Nabble.com. __ R-help@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. -- Andrew Robinson Department of Mathematics and StatisticsTel: +61-3-8344-9763 University of Melbourne, VIC 3010 Australia Fax: +61-3-8344-4599 http://www.ms.unimelb.edu.au/~andrewpr http://blogs.mbs.edu/fishing-in-the-bay/ __ R-help@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. -- View this message in context: http://www.nabble.com/Numbers-with-correct-significant-digits-tf2657246.html#a7412784 Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
[R] Plot title with numeric variables
I am trying to create a plot title in R with substitution by a numeric variable (Figure number N) within the text which is bold and has a subcripted part as well. Here is what I have: title - expression(bold(paste(Figure , N, : Plot , C[max], versus CrCL))) plot(1, main=) # Simple plot for testing N - 5 mtext(title, line=3, font=2, cex=1.25) I have the bold part and the subscripted text worked out but how do I replace the text N in the title by its numeric value (5 in this example)? I tried all kinds of stuff with substitute, etc. but can't figure it out. The last 3 lines are actually from a function with title as argument. N is internal to the function and changes. Any help is much appreciated. Thanks. Rene -- View this message in context: http://www.nabble.com/Plot-title-with-numeric-variables-tf2631678.html#a7344545 Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] Plot title with numeric variables
This works for the original posted question: n-5 title - bquote(bold(paste(Figure , .(n), : Plot , C[max], versus CrCl))) plot(1, main=title) However, my problem is that I want to define the text before the value of n is known. The idea is that the title is defined ahead, passed to a function that makes many plots, and n is incremented for each plot. One way to accomplish this would be to have the constant part of the title defined ahead: fff - bquote(paste(Plot , C[max], versus CrCl)) Unfortunanely, I need to use bquote() or expression() in order to get the subscript correctly (subscript in the wordprocessing sense = text placed a little bit lower than normal). And then add to this the changing part at the time the plot is made (when the value of n is correct). The changing part is: ccc - bquote(paste(Figure , .(n), :)) Unfortunatley, I need to use bquote() or substitute() here to replace n with it's numeric value. This can actually be done simplier: paste(Figure, n, :) I just don't know how to concatenate both fff and ccc to create the title. I am wondering whether it is possible to construct variables or strings that contain the text plus the special charaters for subscript (square brackets) and the code for replacement of n by its numeric value, and then evaluate the combination as part of a substitute() function. As a try that does not work: fff - expression(paste(Plot ,C[max], versus CrCl)) # Need expression() for subscript text n-5 ccc - bquote(paste(Figure , .(n), :)) # Need bquote() for replacement of n; can be done with substitute() also, or simple: paste(Figure, n, :) title - paste(fff, ccc) # Does not work; produces strange results in plot title # plot(1, main=title) LARGER PEROBLEM: My larger problem is to construct a number of plots in sets with the same title per set (fixed part per set) but with the title number incremented with 1 starting with 1 (variable part). I wanted to define the fixed part of the title in the main loop but have the figure counter rolling in a function just before each plot is constructed at which time the figure number is known. Very ackward, but this works as the main loop: numSetsOfPlots - 1:2 numPlotsPerSet - 1:3 n - 0 for (setNo in numSetsOfPlots) { for (plotInSetNo in numPlotsPerSet) { n - n + 1 if (setNo == 1) myTitle - bquote(paste(Figure , .(n), : , C[max])) if (setNo == 2) myTitle - bquote(paste(Figure , .(n), : , AUC)) plot(1, main=myTitle) # Will be a call to a more complex plot function readline('Press Enter to proceed...') } } At this point, I can NOT separate a Figure counter from the fixed part of the title. Both have to be combined in the same main loop. The need for the subscript for which a PlotMath function is needed causes this problem. -- Rene Braeckman, PhD (RMan54) Irvine, CA RMan54 wrote: I am trying to create a plot title in R with substitution by a numeric variable (Figure number N) within the text which is bold and has a subcripted part as well. Here is what I have: title - expression(bold(paste(Figure , N, : Plot , C[max], versus CrCL))) plot(1, main=) # Simple plot for testing N - 5 mtext(title, line=3, font=2, cex=1.25) I have the bold part and the subscripted text worked out but how do I replace the text N in the title by its numeric value (5 in this example)? I tried all kinds of stuff with substitute, etc. but can't figure it out. The last 3 lines are actually from a function with title as argument. N is internal to the function and changes. Any help is much appreciated. Thanks. Rene -- View this message in context: http://www.nabble.com/Plot-title-with-numeric-variables-tf2631678.html#a7350682 Sent from the R help mailing list archive at Nabble.com. __ R-help@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.