Re: [R] Add annotation text outside of an xyplot (lattice package)
You can find an example of annotating lattice graphics with text anywhere on the graphics device using the pagenum package. See the vignette here: https://cran.r-project.org/web/packages/pagenum/vignettes/pagenum.html The pagenum package uses the grid package to add viewports for the annotation. The R code showing how this works is here: https://github.com/kwstat/pagenum/blob/master/R/pagenum.r Kevin Wright On Thu, Sep 22, 2016 at 9:04 AM, Jun Shenwrote: > Dear list, > > Just wonder if there is a way to add annotation text outside an xyplot, > (e.g. the bottom of the plot). the panel.text seems only add text within > the plot. Thanks. > > Jun > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. > -- Kevin Wright [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] Add annotation text outside of an xyplot (lattice package)
Hi Richard, Thanks for demonstrating the usage of layer in latticeExtra. In my current case I do have multiple panels on one page but only need some universal annotation text for the whole page. So "sub" argument does the job pretty well. You have certainly shown a very interesting example to add different annotation text for each panel. This is very useful when such text is needed. Thank everyone for the help. Best regards, Jun On Sun, Sep 25, 2016 at 5:18 PM, Richard M. Heibergerwrote: > Bert, > > I interpreted the OP's request as a single panel xyplot. > The latticeExtra::layer mechanism does work for multiple plots. > > > library(lattice) > library(latticeExtra) > tmp <- data.frame(x=1:10, y=1:10, g=rep(c("A","B"), each=5)) > > xyplot(y ~ x | g, data=tmp) > > xyplot(y ~ x | g, data=tmp, main="outside text displayed", >par.settings=list(clip=list(panel=FALSE))) + > latticeExtra::layer(panel.text(x=2, y=-0.5, label="very interesting")) > > xyplot(y ~ x | g, data=tmp, main="outside text displayed", >par.settings=list(clip=list(panel=FALSE))) + > latticeExtra::layer(panel.text(x=2, y=-0.5, >label=c("very interesting", "also interesting")[panel.number()])) > > > For the overall lattice display I agree that the mechanisms you > suggested are approriate. > > Rich > > > On Sun, Sep 25, 2016 at 4:34 PM, Bert Gunter > wrote: > > ... but what if there are multiple panels? > > > > "The layer mechanism is a method for augmenting a panel function. It > > allows expressions to be added to the panel function without knowing > > what the original panel function was. " > > > > As I understand it, the OP requested annotation for the entire lattice > > display, not single panels thereof. This seems more like a "sub" or > > "legend" addition. > > > > Cheers, > > Bert > > Bert Gunter > > > > "The trouble with having an open mind is that people keep coming along > > and sticking things into it." > > -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) > > > > > > On Sun, Sep 25, 2016 at 11:44 AM, Richard M. Heiberger > wrote: > >> library(lattice) > >> library(latticeExtra) > >> tmp <- data.frame(x=1:10, y=1:10) > >> > >> xyplot(y ~ x, data=tmp) > >> > >> xyplot(y ~ x, data=tmp, main="text outside panel clipped") + > >> ## "+" must be on same line as first statement. > >> ## This use of "+" is from latticeExtra. > >> latticeExtra::layer(panel.text(x=2, y=-0.5, label="very > interesting")) > >> > >> xyplot(y ~ x, data=tmp, main="outside text displayed", > >>par.settings=list(clip=list(panel=FALSE)) ## permit text > >> outside the panel > >> ) + > >> ## "+" must be on same line as first statement. > >> ## This use of "+" is from latticeExtra. > >> latticeExtra::layer(panel.text(x=2, y=-0.5, label="very > interesting")) > >> > >> ## I use the phrasing "latticeExtra::layer", not the simpler "layer". > >> ## latticeExtra and ggplot2 both use layer and they use it incompatibly. > >> ## It is possible for both packages to be loaded at the same time, > therefore > >> ## I specify latticeExtra explicitly. > >> > >> ## ltext and panel.text are the same. > >> > >> > >> On Sun, Sep 25, 2016 at 12:32 PM, Jun Shen > wrote: > >>> Thanks Bert, sub works pretty well. > >>> > >>> Carlos, thanks for the suggestion. As I am not familiar with > latticeExatra, > >>> not sure how hard it is to make it work with my plot. I'll try. > >>> > >>> On Sat, Sep 24, 2016 at 11:04 AM, Bert Gunter > >>> wrote: > >>> > No. > > ltext/panel.text plots text *within* panels; IIUC, the OP requested > text outside the plots. For that see the details for "main" and/or > "sub" in ?xyplot. I think it could also be done more flexibly via a > legend or a key with a title but no content -- again, see the Help > page -- but haven't tried it. > > Cheers, > Bert > > > Bert Gunter > > "The trouble with having an open mind is that people keep coming along > and sticking things into it." > -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) > > > On Fri, Sep 23, 2016 at 11:49 PM, Rainer Hurling > wrote: > > Hi, > > > > one possible solution is to use ltext(). > > > > ltext(xcoord, ycoord, label="TEST", adj=c(0.5,0.5)) > > > > You have to know or to find out best fitting coordinates. > > > > Via adj you can control, if the text should adjust left, center or > right > > to the coords, and above, center or bottom of them. > > > > HTH, > > Rainer Hurling > > > > > > Am 22.09.2016 um 16:04 schrieb Jun Shen: > >> Dear list, > >> > >> Just wonder if there is a way to add annotation text outside an > xyplot, > >> (e.g. the bottom of the plot). the
Re: [R] Add annotation text outside of an xyplot (lattice package)
Bert, I interpreted the OP's request as a single panel xyplot. The latticeExtra::layer mechanism does work for multiple plots. library(lattice) library(latticeExtra) tmp <- data.frame(x=1:10, y=1:10, g=rep(c("A","B"), each=5)) xyplot(y ~ x | g, data=tmp) xyplot(y ~ x | g, data=tmp, main="outside text displayed", par.settings=list(clip=list(panel=FALSE))) + latticeExtra::layer(panel.text(x=2, y=-0.5, label="very interesting")) xyplot(y ~ x | g, data=tmp, main="outside text displayed", par.settings=list(clip=list(panel=FALSE))) + latticeExtra::layer(panel.text(x=2, y=-0.5, label=c("very interesting", "also interesting")[panel.number()])) For the overall lattice display I agree that the mechanisms you suggested are approriate. Rich On Sun, Sep 25, 2016 at 4:34 PM, Bert Gunterwrote: > ... but what if there are multiple panels? > > "The layer mechanism is a method for augmenting a panel function. It > allows expressions to be added to the panel function without knowing > what the original panel function was. " > > As I understand it, the OP requested annotation for the entire lattice > display, not single panels thereof. This seems more like a "sub" or > "legend" addition. > > Cheers, > Bert > Bert Gunter > > "The trouble with having an open mind is that people keep coming along > and sticking things into it." > -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) > > > On Sun, Sep 25, 2016 at 11:44 AM, Richard M. Heiberger > wrote: >> library(lattice) >> library(latticeExtra) >> tmp <- data.frame(x=1:10, y=1:10) >> >> xyplot(y ~ x, data=tmp) >> >> xyplot(y ~ x, data=tmp, main="text outside panel clipped") + >> ## "+" must be on same line as first statement. >> ## This use of "+" is from latticeExtra. >> latticeExtra::layer(panel.text(x=2, y=-0.5, label="very interesting")) >> >> xyplot(y ~ x, data=tmp, main="outside text displayed", >>par.settings=list(clip=list(panel=FALSE)) ## permit text >> outside the panel >> ) + >> ## "+" must be on same line as first statement. >> ## This use of "+" is from latticeExtra. >> latticeExtra::layer(panel.text(x=2, y=-0.5, label="very interesting")) >> >> ## I use the phrasing "latticeExtra::layer", not the simpler "layer". >> ## latticeExtra and ggplot2 both use layer and they use it incompatibly. >> ## It is possible for both packages to be loaded at the same time, therefore >> ## I specify latticeExtra explicitly. >> >> ## ltext and panel.text are the same. >> >> >> On Sun, Sep 25, 2016 at 12:32 PM, Jun Shen wrote: >>> Thanks Bert, sub works pretty well. >>> >>> Carlos, thanks for the suggestion. As I am not familiar with latticeExatra, >>> not sure how hard it is to make it work with my plot. I'll try. >>> >>> On Sat, Sep 24, 2016 at 11:04 AM, Bert Gunter >>> wrote: >>> No. ltext/panel.text plots text *within* panels; IIUC, the OP requested text outside the plots. For that see the details for "main" and/or "sub" in ?xyplot. I think it could also be done more flexibly via a legend or a key with a title but no content -- again, see the Help page -- but haven't tried it. Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Fri, Sep 23, 2016 at 11:49 PM, Rainer Hurling wrote: > Hi, > > one possible solution is to use ltext(). > > ltext(xcoord, ycoord, label="TEST", adj=c(0.5,0.5)) > > You have to know or to find out best fitting coordinates. > > Via adj you can control, if the text should adjust left, center or right > to the coords, and above, center or bottom of them. > > HTH, > Rainer Hurling > > > Am 22.09.2016 um 16:04 schrieb Jun Shen: >> Dear list, >> >> Just wonder if there is a way to add annotation text outside an xyplot, >> (e.g. the bottom of the plot). the panel.text seems only add text within >> the plot. Thanks. >> >> Jun > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. >>> >>> [[alternative HTML version deleted]] >>> >>> __ >>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >>> 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,
Re: [R] Add annotation text outside of an xyplot (lattice package)
... but what if there are multiple panels? "The layer mechanism is a method for augmenting a panel function. It allows expressions to be added to the panel function without knowing what the original panel function was. " As I understand it, the OP requested annotation for the entire lattice display, not single panels thereof. This seems more like a "sub" or "legend" addition. Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Sun, Sep 25, 2016 at 11:44 AM, Richard M. Heibergerwrote: > library(lattice) > library(latticeExtra) > tmp <- data.frame(x=1:10, y=1:10) > > xyplot(y ~ x, data=tmp) > > xyplot(y ~ x, data=tmp, main="text outside panel clipped") + > ## "+" must be on same line as first statement. > ## This use of "+" is from latticeExtra. > latticeExtra::layer(panel.text(x=2, y=-0.5, label="very interesting")) > > xyplot(y ~ x, data=tmp, main="outside text displayed", >par.settings=list(clip=list(panel=FALSE)) ## permit text > outside the panel > ) + > ## "+" must be on same line as first statement. > ## This use of "+" is from latticeExtra. > latticeExtra::layer(panel.text(x=2, y=-0.5, label="very interesting")) > > ## I use the phrasing "latticeExtra::layer", not the simpler "layer". > ## latticeExtra and ggplot2 both use layer and they use it incompatibly. > ## It is possible for both packages to be loaded at the same time, therefore > ## I specify latticeExtra explicitly. > > ## ltext and panel.text are the same. > > > On Sun, Sep 25, 2016 at 12:32 PM, Jun Shen wrote: >> Thanks Bert, sub works pretty well. >> >> Carlos, thanks for the suggestion. As I am not familiar with latticeExatra, >> not sure how hard it is to make it work with my plot. I'll try. >> >> On Sat, Sep 24, 2016 at 11:04 AM, Bert Gunter >> wrote: >> >>> No. >>> >>> ltext/panel.text plots text *within* panels; IIUC, the OP requested >>> text outside the plots. For that see the details for "main" and/or >>> "sub" in ?xyplot. I think it could also be done more flexibly via a >>> legend or a key with a title but no content -- again, see the Help >>> page -- but haven't tried it. >>> >>> Cheers, >>> Bert >>> >>> >>> Bert Gunter >>> >>> "The trouble with having an open mind is that people keep coming along >>> and sticking things into it." >>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) >>> >>> >>> On Fri, Sep 23, 2016 at 11:49 PM, Rainer Hurling wrote: >>> > Hi, >>> > >>> > one possible solution is to use ltext(). >>> > >>> > ltext(xcoord, ycoord, label="TEST", adj=c(0.5,0.5)) >>> > >>> > You have to know or to find out best fitting coordinates. >>> > >>> > Via adj you can control, if the text should adjust left, center or right >>> > to the coords, and above, center or bottom of them. >>> > >>> > HTH, >>> > Rainer Hurling >>> > >>> > >>> > Am 22.09.2016 um 16:04 schrieb Jun Shen: >>> >> Dear list, >>> >> >>> >> Just wonder if there is a way to add annotation text outside an xyplot, >>> >> (e.g. the bottom of the plot). the panel.text seems only add text within >>> >> the plot. Thanks. >>> >> >>> >> Jun >>> > >>> > __ >>> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >>> > 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. >>> >> >> [[alternative HTML version deleted]] >> >> __ >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> 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 -- To UNSUBSCRIBE and more, see 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] Add annotation text outside of an xyplot (lattice package)
library(lattice) library(latticeExtra) tmp <- data.frame(x=1:10, y=1:10) xyplot(y ~ x, data=tmp) xyplot(y ~ x, data=tmp, main="text outside panel clipped") + ## "+" must be on same line as first statement. ## This use of "+" is from latticeExtra. latticeExtra::layer(panel.text(x=2, y=-0.5, label="very interesting")) xyplot(y ~ x, data=tmp, main="outside text displayed", par.settings=list(clip=list(panel=FALSE)) ## permit text outside the panel ) + ## "+" must be on same line as first statement. ## This use of "+" is from latticeExtra. latticeExtra::layer(panel.text(x=2, y=-0.5, label="very interesting")) ## I use the phrasing "latticeExtra::layer", not the simpler "layer". ## latticeExtra and ggplot2 both use layer and they use it incompatibly. ## It is possible for both packages to be loaded at the same time, therefore ## I specify latticeExtra explicitly. ## ltext and panel.text are the same. On Sun, Sep 25, 2016 at 12:32 PM, Jun Shenwrote: > Thanks Bert, sub works pretty well. > > Carlos, thanks for the suggestion. As I am not familiar with latticeExatra, > not sure how hard it is to make it work with my plot. I'll try. > > On Sat, Sep 24, 2016 at 11:04 AM, Bert Gunter > wrote: > >> No. >> >> ltext/panel.text plots text *within* panels; IIUC, the OP requested >> text outside the plots. For that see the details for "main" and/or >> "sub" in ?xyplot. I think it could also be done more flexibly via a >> legend or a key with a title but no content -- again, see the Help >> page -- but haven't tried it. >> >> Cheers, >> Bert >> >> >> Bert Gunter >> >> "The trouble with having an open mind is that people keep coming along >> and sticking things into it." >> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) >> >> >> On Fri, Sep 23, 2016 at 11:49 PM, Rainer Hurling wrote: >> > Hi, >> > >> > one possible solution is to use ltext(). >> > >> > ltext(xcoord, ycoord, label="TEST", adj=c(0.5,0.5)) >> > >> > You have to know or to find out best fitting coordinates. >> > >> > Via adj you can control, if the text should adjust left, center or right >> > to the coords, and above, center or bottom of them. >> > >> > HTH, >> > Rainer Hurling >> > >> > >> > Am 22.09.2016 um 16:04 schrieb Jun Shen: >> >> Dear list, >> >> >> >> Just wonder if there is a way to add annotation text outside an xyplot, >> >> (e.g. the bottom of the plot). the panel.text seems only add text within >> >> the plot. Thanks. >> >> >> >> Jun >> > >> > __ >> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> > 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. >> > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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 -- To UNSUBSCRIBE and more, see 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] Add annotation text outside of an xyplot (lattice package)
Thanks Bert, sub works pretty well. Carlos, thanks for the suggestion. As I am not familiar with latticeExatra, not sure how hard it is to make it work with my plot. I'll try. On Sat, Sep 24, 2016 at 11:04 AM, Bert Gunterwrote: > No. > > ltext/panel.text plots text *within* panels; IIUC, the OP requested > text outside the plots. For that see the details for "main" and/or > "sub" in ?xyplot. I think it could also be done more flexibly via a > legend or a key with a title but no content -- again, see the Help > page -- but haven't tried it. > > Cheers, > Bert > > > Bert Gunter > > "The trouble with having an open mind is that people keep coming along > and sticking things into it." > -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) > > > On Fri, Sep 23, 2016 at 11:49 PM, Rainer Hurling wrote: > > Hi, > > > > one possible solution is to use ltext(). > > > > ltext(xcoord, ycoord, label="TEST", adj=c(0.5,0.5)) > > > > You have to know or to find out best fitting coordinates. > > > > Via adj you can control, if the text should adjust left, center or right > > to the coords, and above, center or bottom of them. > > > > HTH, > > Rainer Hurling > > > > > > Am 22.09.2016 um 16:04 schrieb Jun Shen: > >> Dear list, > >> > >> Just wonder if there is a way to add annotation text outside an xyplot, > >> (e.g. the bottom of the plot). the panel.text seems only add text within > >> the plot. Thanks. > >> > >> Jun > > > > __ > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > > 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. > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] Add annotation text outside of an xyplot (lattice package)
No. ltext/panel.text plots text *within* panels; IIUC, the OP requested text outside the plots. For that see the details for "main" and/or "sub" in ?xyplot. I think it could also be done more flexibly via a legend or a key with a title but no content -- again, see the Help page -- but haven't tried it. Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Fri, Sep 23, 2016 at 11:49 PM, Rainer Hurlingwrote: > Hi, > > one possible solution is to use ltext(). > > ltext(xcoord, ycoord, label="TEST", adj=c(0.5,0.5)) > > You have to know or to find out best fitting coordinates. > > Via adj you can control, if the text should adjust left, center or right > to the coords, and above, center or bottom of them. > > HTH, > Rainer Hurling > > > Am 22.09.2016 um 16:04 schrieb Jun Shen: >> Dear list, >> >> Just wonder if there is a way to add annotation text outside an xyplot, >> (e.g. the bottom of the plot). the panel.text seems only add text within >> the plot. Thanks. >> >> Jun > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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 -- To UNSUBSCRIBE and more, see 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] Add annotation text outside of an xyplot (lattice package)
Hi, one possible solution is to use ltext(). ltext(xcoord, ycoord, label="TEST", adj=c(0.5,0.5)) You have to know or to find out best fitting coordinates. Via adj you can control, if the text should adjust left, center or right to the coords, and above, center or bottom of them. HTH, Rainer Hurling Am 22.09.2016 um 16:04 schrieb Jun Shen: > Dear list, > > Just wonder if there is a way to add annotation text outside an xyplot, > (e.g. the bottom of the plot). the panel.text seems only add text within > the plot. Thanks. > > Jun __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] Add annotation text outside of an xyplot (lattice package)
Hi, Yes, you can use "latticeExtra" package and use a text layer on top of your current chart. Thanks, Carlos Ortega 2016-09-22 16:04 GMT+02:00 Jun Shen: > Dear list, > > Just wonder if there is a way to add annotation text outside an xyplot, > (e.g. the bottom of the plot). the panel.text seems only add text within > the plot. Thanks. > > Jun > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. > -- Saludos, Carlos Ortega www.qualityexcellence.es [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] Add annotation text outside of an xyplot (lattice package)
Dear list, Just wonder if there is a way to add annotation text outside an xyplot, (e.g. the bottom of the plot). the panel.text seems only add text within the plot. Thanks. Jun [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.