show 0 at y axis in xyplot lattice

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

show 0 at y axis in xyplot lattice

R help mailing list-2
Dear all
I am trying to make a plot in xyplot lattice by groups. I would like to show "0" in y axis but I don't want to be aligned with the x axis. I want to be a little bit above.
I have tried many options but I don't get what I want. I also tried ylim=c(0, 80) but both 0 and 80 are fully aligned with the x-axis and the upper boundary of the plot, respectively:
xyplot(upper.zn + Zn2 + lower.zn ~ sdate | Location, type="b", as.table=TRUE, data=dat, pch=c(22, 21, 22), lty=c(2, 1, 2), ylim=c(0, 80),
       index.cond=list(c(3, 1, 2)), ylab="Percent (%)", par.strip.text=list(col="white", font=2, lines=1.5),
       lattice.options = modifyList(lattice.options(), list(skip.boundary.labels = 0)),
       par.settings=my.settings, col=c("red", "black", "red"), fill=c("red", "black", "red"),
       key=dat_key, scales = list(x = list(at = sdate, labels = format(sdate, "%b-%y"))), xlab="Date",
       panel = function(x, y, ...) {
         panel.grid(h = -1, v = 0, lwd=1, lty=3, col="grey")              
         panel.abline(v=sdate, lwd=1, lty=3, col="grey")             
         panel.xyplot(x, y, ...)
         }
         )
when I use the following, 80 is a bit lower than the upper boundary of the plot, which is what I want, but 0 is not showing: 
xyplot(upper.zn + Zn2 + lower.zn ~ sdate | Location, type="b", as.table=TRUE, data=dat, pch=c(22, 21, 22), lty=c(2, 1, 2),
       index.cond=list(c(3, 1, 2)), ylab="Percent (%)", par.strip.text=list(col="white", font=2, lines=1.5),
       lattice.options = modifyList(lattice.options(), list(skip.boundary.labels = 0)),
       par.settings=my.settings, col=c("red", "black", "red"), fill=c("red", "black", "red"),
       key=dat_key, scales = list(x = list(at = sdate, labels = format(sdate, "%b-%y")), y=list(at=c(0, 20, 40, 60, 80))), xlab="Date",
       panel = function(x, y, ...) {
         panel.grid(h = -1, v = 0, lwd=1, lty=3, col="grey")              
         panel.abline(v=sdate, lwd=1, lty=3, col="grey")             
         panel.xyplot(x, y, ...)
         }
         )I have also attached a reproducible example in case you want to see in more detail my data. 
I would very much appreciate any suggestions on this. 
Thank you in advance.
Kind regards,Maria
______________________________________________
[hidden email] 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.

savedat.txt (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: show 0 at y axis in xyplot lattice

Bert Gunter-2
1. Not reproducible since my.settings, dat_key, sdate not provided.

2. Why did you not try something like ylim = c(-5,80)  ?


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 Mon, Sep 11, 2017 at 12:33 PM, Maria Lathouri via R-help <
[hidden email]> wrote:

> Dear all
> I am trying to make a plot in xyplot lattice by groups. I would like to
> show "0" in y axis but I don't want to be aligned with the x axis. I want
> to be a little bit above.
> I have tried many options but I don't get what I want. I also tried
> ylim=c(0, 80) but both 0 and 80 are fully aligned with the x-axis and the
> upper boundary of the plot, respectively:
> xyplot(upper.zn + Zn2 + lower.zn ~ sdate | Location, type="b",
> as.table=TRUE, data=dat, pch=c(22, 21, 22), lty=c(2, 1, 2), ylim=c(0, 80),
>        index.cond=list(c(3, 1, 2)), ylab="Percent (%)",
> par.strip.text=list(col="white", font=2, lines=1.5),
>        lattice.options = modifyList(lattice.options(),
> list(skip.boundary.labels = 0)),
>        par.settings=my.settings, col=c("red", "black", "red"),
> fill=c("red", "black", "red"),
>        key=dat_key, scales = list(x = list(at = sdate, labels =
> format(sdate, "%b-%y"))), xlab="Date",
>        panel = function(x, y, ...) {
>          panel.grid(h = -1, v = 0, lwd=1, lty=3, col="grey")
>          panel.abline(v=sdate, lwd=1, lty=3, col="grey")
>          panel.xyplot(x, y, ...)
>          }
>          )
> when I use the following, 80 is a bit lower than the upper boundary of the
> plot, which is what I want, but 0 is not showing:
> xyplot(upper.zn + Zn2 + lower.zn ~ sdate | Location, type="b",
> as.table=TRUE, data=dat, pch=c(22, 21, 22), lty=c(2, 1, 2),
>        index.cond=list(c(3, 1, 2)), ylab="Percent (%)",
> par.strip.text=list(col="white", font=2, lines=1.5),
>        lattice.options = modifyList(lattice.options(),
> list(skip.boundary.labels = 0)),
>        par.settings=my.settings, col=c("red", "black", "red"),
> fill=c("red", "black", "red"),
>        key=dat_key, scales = list(x = list(at = sdate, labels =
> format(sdate, "%b-%y")), y=list(at=c(0, 20, 40, 60, 80))), xlab="Date",
>        panel = function(x, y, ...) {
>          panel.grid(h = -1, v = 0, lwd=1, lty=3, col="grey")
>          panel.abline(v=sdate, lwd=1, lty=3, col="grey")
>          panel.xyplot(x, y, ...)
>          }
>          )I have also attached a reproducible example in case you want to
> see in more detail my data.
> I would very much appreciate any suggestions on this.
> Thank you in advance.
> Kind regards,Maria
> ______________________________________________
> [hidden email] 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]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Σχετ: show 0 at y axis in xyplot lattice

R help mailing list-2
Dear Bert and all,
I am really sorry. This is the full code:
dat<-read.csv("example.csv")attach(dat)
sdate<-as.Date(Date, format="%Y-%m-%d")
#change the colour of the strip background
my.settings <- canonical.theme(color=FALSE)
my.settings[['strip.background']]$col <- "blue"
dat_key <- list(space="right",
                lines = list(type = c("b", "b", "b"), pch=c(22, 21, 22), col = c("red", "black", "red"),
                             fill=c("red", "black", "red"), lwd=1, lty=c(2, 1, 2)),
                text = list((c("upper se", (expression(paste(Zn^paste(2,"+")))), "lower se"))))
xyplot(upper.zn + Zn2 + lower.zn ~ sdate | Location, type="b", as.table=TRUE, data=dat, pch=c(22, 21, 22), lty=c(2, 1, 2),
       index.cond=list(c(3, 1, 2)), ylab="Percent (%)", par.strip.text=list(col="white", font=2, lines=1.5),
       lattice.options = modifyList(lattice.options(), list(skip.boundary.labels = 0)),
       par.settings=my.settings, col=c("red", "black", "red"), fill=c("red", "black", "red"),
       key=dat_key, scales = list(x = list(at = sdate, labels = format(sdate, "%b-%y")), y=list(at=c(0, 20, 40, 60, 80))), xlab="Date",
       panel = function(x, y, ...) {
         panel.grid(h = -1, v = 0, lwd=1, lty=3, col="grey")              
         panel.abline(v=sdate, lwd=1, lty=3, col="grey")             
         panel.xyplot(x, y, ...)
         }
         )
Hope this helps. 
Kind regards,Maria

    Στις 10:15 μ.μ. Δευτέρα, 11 Σεπτεμβρίου 2017, ο/η Bert Gunter <[hidden email]> έγραψε:
 

 1. Not reproducible since my.settings, dat_key, sdate not provided.

2. Why did you not try something like ylim = c(-5,80)  ?


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 Mon, Sep 11, 2017 at 12:33 PM, Maria Lathouri via R-help <[hidden email]> wrote:

Dear all
I am trying to make a plot in xyplot lattice by groups. I would like to show "0" in y axis but I don't want to be aligned with the x axis. I want to be a little bit above.
I have tried many options but I don't get what I want. I also tried ylim=c(0, 80) but both 0 and 80 are fully aligned with the x-axis and the upper boundary of the plot, respectively:
xyplot(upper.zn + Zn2 + lower.zn ~ sdate | Location, type="b", as.table=TRUE, data=dat, pch=c(22, 21, 22), lty=c(2, 1, 2), ylim=c(0, 80),
       index.cond=list(c(3, 1, 2)), ylab="Percent (%)", par.strip.text=list(col=" white", font=2, lines=1.5),
       lattice.options = modifyList(lattice.options(), list(skip.boundary.labels = 0)),
       par.settings=my.settings, col=c("red", "black", "red"), fill=c("red", "black", "red"),
       key=dat_key, scales = list(x = list(at = sdate, labels = format(sdate, "%b-%y"))), xlab="Date",
       panel = function(x, y, ...) {
         panel.grid(h = -1, v = 0, lwd=1, lty=3, col="grey")              
         panel.abline(v=sdate, lwd=1, lty=3, col="grey")             
         panel.xyplot(x, y, ...)
         }
         )
when I use the following, 80 is a bit lower than the upper boundary of the plot, which is what I want, but 0 is not showing: 
xyplot(upper.zn + Zn2 + lower.zn ~ sdate | Location, type="b", as.table=TRUE, data=dat, pch=c(22, 21, 22), lty=c(2, 1, 2),
       index.cond=list(c(3, 1, 2)), ylab="Percent (%)", par.strip.text=list(col=" white", font=2, lines=1.5),
       lattice.options = modifyList(lattice.options(), list(skip.boundary.labels = 0)),
       par.settings=my.settings, col=c("red", "black", "red"), fill=c("red", "black", "red"),
       key=dat_key, scales = list(x = list(at = sdate, labels = format(sdate, "%b-%y")), y=list(at=c(0, 20, 40, 60, 80))), xlab="Date",
       panel = function(x, y, ...) {
         panel.grid(h = -1, v = 0, lwd=1, lty=3, col="grey")              
         panel.abline(v=sdate, lwd=1, lty=3, col="grey")             
         panel.xyplot(x, y, ...)
         }
         )I have also attached a reproducible example in case you want to see in more detail my data. 
I would very much appreciate any suggestions on this. 
Thank you in advance.
Kind regards,Maria
______________________________ ________________
[hidden email] 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]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: show 0 at y axis in xyplot lattice

Bert Gunter-2
Not reproducible, as we have neither "example.csv" nor "Date" .

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 Mon, Sep 11, 2017 at 2:38 PM, Maria Lathouri <[hidden email]> wrote:

> Dear Bert and all,
>
> I am really sorry. This is the full code:
>
> dat<-read.csv("example.csv")
> attach(dat)
>
> sdate<-as.Date(Date, format="%Y-%m-%d")
>
> #change the colour of the strip background
> my.settings <- canonical.theme(color=FALSE)
> my.settings[['strip.background']]$col <- "blue"
>
> dat_key <- list(space="right",
>                 lines = list(type = c("b", "b", "b"), pch=c(22, 21, 22),
> col = c("red", "black", "red"),
>                              fill=c("red", "black", "red"), lwd=1,
> lty=c(2, 1, 2)),
>                 text = list((c("upper se", (expression(paste(Zn^paste(2,"+")))),
> "lower se"))))
>
> xyplot(upper.zn + Zn2 + lower.zn ~ sdate | Location, type="b",
> as.table=TRUE, data=dat, pch=c(22, 21, 22), lty=c(2, 1, 2),
>        index.cond=list(c(3, 1, 2)), ylab="Percent (%)",
> par.strip.text=list(col="white", font=2, lines=1.5),
>        lattice.options = modifyList(lattice.options(),
> list(skip.boundary.labels = 0)),
>        par.settings=my.settings, col=c("red", "black", "red"),
> fill=c("red", "black", "red"),
>        key=dat_key, scales = list(x = list(at = sdate, labels =
> format(sdate, "%b-%y")), y=list(at=c(0, 20, 40, 60, 80))), xlab="Date",
>        panel = function(x, y, ...) {
>          panel.grid(h = -1, v = 0, lwd=1, lty=3, col="grey")
>          panel.abline(v=sdate, lwd=1, lty=3, col="grey")
>          panel.xyplot(x, y, ...)
>          }
>          )
>
> Hope this helps.
>
> Kind regards,
> Maria
>
>
> Στις 10:15 μ.μ. Δευτέρα, 11 Σεπτεμβρίου 2017, ο/η Bert Gunter <
> [hidden email]> έγραψε:
>
>
> 1. Not reproducible since my.settings, dat_key, sdate not provided.
>
> 2. Why did you not try something like ylim = c(-5,80)  ?
>
>
> 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 Mon, Sep 11, 2017 at 12:33 PM, Maria Lathouri via R-help <
> [hidden email]> wrote:
>
> Dear all
> I am trying to make a plot in xyplot lattice by groups. I would like to
> show "0" in y axis but I don't want to be aligned with the x axis. I want
> to be a little bit above.
> I have tried many options but I don't get what I want. I also tried
> ylim=c(0, 80) but both 0 and 80 are fully aligned with the x-axis and the
> upper boundary of the plot, respectively:
> xyplot(upper.zn + Zn2 + lower.zn ~ sdate | Location, type="b",
> as.table=TRUE, data=dat, pch=c(22, 21, 22), lty=c(2, 1, 2), ylim=c(0, 80),
>        index.cond=list(c(3, 1, 2)), ylab="Percent (%)",
> par.strip.text=list(col=" white", font=2, lines=1.5),
>        lattice.options = modifyList(lattice.options(),
> list(skip.boundary.labels = 0)),
>        par.settings=my.settings, col=c("red", "black", "red"),
> fill=c("red", "black", "red"),
>        key=dat_key, scales = list(x = list(at = sdate, labels =
> format(sdate, "%b-%y"))), xlab="Date",
>        panel = function(x, y, ...) {
>          panel.grid(h = -1, v = 0, lwd=1, lty=3, col="grey")
>          panel.abline(v=sdate, lwd=1, lty=3, col="grey")
>          panel.xyplot(x, y, ...)
>          }
>          )
> when I use the following, 80 is a bit lower than the upper boundary of the
> plot, which is what I want, but 0 is not showing:
> xyplot(upper.zn + Zn2 + lower.zn ~ sdate | Location, type="b",
> as.table=TRUE, data=dat, pch=c(22, 21, 22), lty=c(2, 1, 2),
>        index.cond=list(c(3, 1, 2)), ylab="Percent (%)",
> par.strip.text=list(col=" white", font=2, lines=1.5),
>        lattice.options = modifyList(lattice.options(),
> list(skip.boundary.labels = 0)),
>        par.settings=my.settings, col=c("red", "black", "red"),
> fill=c("red", "black", "red"),
>        key=dat_key, scales = list(x = list(at = sdate, labels =
> format(sdate, "%b-%y")), y=list(at=c(0, 20, 40, 60, 80))), xlab="Date",
>        panel = function(x, y, ...) {
>          panel.grid(h = -1, v = 0, lwd=1, lty=3, col="grey")
>          panel.abline(v=sdate, lwd=1, lty=3, col="grey")
>          panel.xyplot(x, y, ...)
>          }
>          )I have also attached a reproducible example in case you want to
> see in more detail my data.
> I would very much appreciate any suggestions on this.
> Thank you in advance.
> Kind regards,Maria
> ______________________________ ________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/ listinfo/r-help
> <https://stat.ethz.ch/mailman/listinfo/r-help>
> PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html <http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>
>
>
>
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: show 0 at y axis in xyplot lattice

Jeff Newmiller
I recommend that Maria read [1], [2] and especially [3], since the latter helps you verify that your example is in fact reproducible before sending it out for us to have problems with and complain about.

[1] http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example

[2] http://adv-r.had.co.nz/Reproducibility.html

[3] https://cran.r-project.org/web/packages/reprex/index.html (read the vignette)

--
Sent from my phone. Please excuse my brevity.

On September 11, 2017 3:50:29 PM PDT, Bert Gunter <[hidden email]> wrote:

>Not reproducible, as we have neither "example.csv" nor "Date" .
>
>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 Mon, Sep 11, 2017 at 2:38 PM, Maria Lathouri <[hidden email]>
>wrote:
>
>> Dear Bert and all,
>>
>> I am really sorry. This is the full code:
>>
>> dat<-read.csv("example.csv")
>> attach(dat)
>>
>> sdate<-as.Date(Date, format="%Y-%m-%d")
>>
>> #change the colour of the strip background
>> my.settings <- canonical.theme(color=FALSE)
>> my.settings[['strip.background']]$col <- "blue"
>>
>> dat_key <- list(space="right",
>>                 lines = list(type = c("b", "b", "b"), pch=c(22, 21,
>22),
>> col = c("red", "black", "red"),
>>                              fill=c("red", "black", "red"), lwd=1,
>> lty=c(2, 1, 2)),
>>                 text = list((c("upper se",
>(expression(paste(Zn^paste(2,"+")))),
>> "lower se"))))
>>
>> xyplot(upper.zn + Zn2 + lower.zn ~ sdate | Location, type="b",
>> as.table=TRUE, data=dat, pch=c(22, 21, 22), lty=c(2, 1, 2),
>>        index.cond=list(c(3, 1, 2)), ylab="Percent (%)",
>> par.strip.text=list(col="white", font=2, lines=1.5),
>>        lattice.options = modifyList(lattice.options(),
>> list(skip.boundary.labels = 0)),
>>        par.settings=my.settings, col=c("red", "black", "red"),
>> fill=c("red", "black", "red"),
>>        key=dat_key, scales = list(x = list(at = sdate, labels =
>> format(sdate, "%b-%y")), y=list(at=c(0, 20, 40, 60, 80))),
>xlab="Date",
>>        panel = function(x, y, ...) {
>>          panel.grid(h = -1, v = 0, lwd=1, lty=3, col="grey")
>>          panel.abline(v=sdate, lwd=1, lty=3, col="grey")
>>          panel.xyplot(x, y, ...)
>>          }
>>          )
>>
>> Hope this helps.
>>
>> Kind regards,
>> Maria
>>
>>
>> Στις 10:15 μ.μ. Δευτέρα, 11 Σεπτεμβρίου 2017, ο/η Bert Gunter <
>> [hidden email]> έγραψε:
>>
>>
>> 1. Not reproducible since my.settings, dat_key, sdate not provided.
>>
>> 2. Why did you not try something like ylim = c(-5,80)  ?
>>
>>
>> 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 Mon, Sep 11, 2017 at 12:33 PM, Maria Lathouri via R-help <
>> [hidden email]> wrote:
>>
>> Dear all
>> I am trying to make a plot in xyplot lattice by groups. I would like
>to
>> show "0" in y axis but I don't want to be aligned with the x axis. I
>want
>> to be a little bit above.
>> I have tried many options but I don't get what I want. I also tried
>> ylim=c(0, 80) but both 0 and 80 are fully aligned with the x-axis and
>the
>> upper boundary of the plot, respectively:
>> xyplot(upper.zn + Zn2 + lower.zn ~ sdate | Location, type="b",
>> as.table=TRUE, data=dat, pch=c(22, 21, 22), lty=c(2, 1, 2), ylim=c(0,
>80),
>>        index.cond=list(c(3, 1, 2)), ylab="Percent (%)",
>> par.strip.text=list(col=" white", font=2, lines=1.5),
>>        lattice.options = modifyList(lattice.options(),
>> list(skip.boundary.labels = 0)),
>>        par.settings=my.settings, col=c("red", "black", "red"),
>> fill=c("red", "black", "red"),
>>        key=dat_key, scales = list(x = list(at = sdate, labels =
>> format(sdate, "%b-%y"))), xlab="Date",
>>        panel = function(x, y, ...) {
>>          panel.grid(h = -1, v = 0, lwd=1, lty=3, col="grey")
>>          panel.abline(v=sdate, lwd=1, lty=3, col="grey")
>>          panel.xyplot(x, y, ...)
>>          }
>>          )
>> when I use the following, 80 is a bit lower than the upper boundary
>of the
>> plot, which is what I want, but 0 is not showing:
>> xyplot(upper.zn + Zn2 + lower.zn ~ sdate | Location, type="b",
>> as.table=TRUE, data=dat, pch=c(22, 21, 22), lty=c(2, 1, 2),
>>        index.cond=list(c(3, 1, 2)), ylab="Percent (%)",
>> par.strip.text=list(col=" white", font=2, lines=1.5),
>>        lattice.options = modifyList(lattice.options(),
>> list(skip.boundary.labels = 0)),
>>        par.settings=my.settings, col=c("red", "black", "red"),
>> fill=c("red", "black", "red"),
>>        key=dat_key, scales = list(x = list(at = sdate, labels =
>> format(sdate, "%b-%y")), y=list(at=c(0, 20, 40, 60, 80))),
>xlab="Date",
>>        panel = function(x, y, ...) {
>>          panel.grid(h = -1, v = 0, lwd=1, lty=3, col="grey")
>>          panel.abline(v=sdate, lwd=1, lty=3, col="grey")
>>          panel.xyplot(x, y, ...)
>>          }
>>          )I have also attached a reproducible example in case you
>want to
>> see in more detail my data.
>> I would very much appreciate any suggestions on this.
>> Thank you in advance.
>> Kind regards,Maria
>> ______________________________ ________________
>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/ listinfo/r-help
>> <https://stat.ethz.ch/mailman/listinfo/r-help>
>> PLEASE do read the posting guide http://www.R-project.org/
>> posting-guide.html <http://www.r-project.org/posting-guide.html>
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
>>
>>
>>
>
> [[alternative HTML version deleted]]
>
>______________________________________________
>[hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: show 0 at y axis in xyplot lattice

Duncan Mackay-4
In reply to this post by R help mailing list-2
Hi Maria

Rule 1 make sure your data is in the right format

dat <- source("G:/1/savedat.txt")
> dat
$value
     Location       Date      Zn2 upper.zn  lower.zn
1    upstream 2016-04-27 29.92477 55.59800 13.912207
2       spill 2016-04-27 12.84040 22.07006  6.964934
3  downstream 2016-04-27 22.49673 41.60901 11.739109
4    upstream 2016-06-28 23.98425 45.60219 10.690640
5       spill 2016-06-28 41.51336 77.99893 20.142426
6  downstream 2016-06-28 15.51232 26.94059  7.044781
7    upstream 2016-08-25 21.73037 40.95852 10.354620
8       spill 2016-08-25 13.42082 22.96901  7.472893
9  downstream 2016-08-25 10.99209 20.17471  5.324318
10   upstream 2016-10-25 20.82462 40.60564  9.602007
11      spill 2016-10-25 14.01283 25.07032  7.830504
12 downstream 2016-10-25 15.67740 30.42278  6.971944
13   upstream 2016-12-21 28.14966 51.79390 14.384139
14      spill 2016-12-21 13.91587 23.94368  8.164688
15 downstream 2016-12-21 13.02749 24.46930  5.826650
16   upstream 2017-02-20 31.16736 55.51858 15.938211
17      spill 2017-02-20 12.47368 22.03830  6.725540
18 downstream 2017-02-20 17.65741 33.23577  8.519928

$visible
[1] TRUE
dat <- dat$value
dat$dDate <- as.Date(as.character(dat$Date))

str(dat)
'data.frame':   18 obs. of  6 variables:
 $ Location: Factor w/ 3 levels "downstream","spill",..: 3 2 1 3 2 1 3 2 1 3 ...
 $ Date    : Factor w/ 6 levels "2016-04-27","2016-06-28",..: 1 1 1 2 2 2 3 3 3 4 ...
 $ Zn2     : num  29.9 12.8 22.5 24 41.5 ...
 $ upper.zn: num  55.6 22.1 41.6 45.6 78 ...
 $ lower.zn: num  13.91 6.96 11.74 10.69 20.14 ...
 $ dDate   : Date, format: "2016-04-27" "2016-04-27" "2016-04-27" "2016-06-28" ...

You code to reproduce the xyplot is not reproducible as it contains user defined objects which you have not included.
Here is something to get you started,
If you want the measurement dates on the x-axis you will need to put the  required dates and format  in the scales argument.
Using par.settings for the symbols an lines will pass those values onto key

xyplot(upper.zn + Zn2 + lower.zn ~ dDate | Location, data=dat,
       type = "b",
       as.table = TRUE,
       par.settings = list(strip.background = list(col = "transparent"),
                           superpose.symbol = list( col=c("red", "black", "red"),
                                              cex = 1,
                                              pch = c(22, 21, 22)),
                           superpose.line = list (col=c("red", "black", "red"),
                                            lty = c(2, 1, 2),
                                            lwd = 1)
                      ),
       auto.key = list(points = TRUE, lines = TRUE),
       scales   = list(x = list(alternating = FALSE,
                                at = seq(from = as.Date("2016-04-01"), to = as.Date("2017-04-01"), by = "quarter"),
                                label = format(seq(from = as.Date("2016-04-01"), to = as.Date("2017-04-01"), by = "quarter"), "%Y %b"),
                                relation    = "same",
                                rot         = 60),
                       y = list(alternating = FALSE,
                                at =  seq(0,80,20),
                                relation    = "same",
                                rot         = 0)
                  ),
#       pch=c(22, 21, 22),
#       lty=c(2, 1, 2),
       xlim = range(seq(from = as.Date("2016-04-01"), to = as.Date("2017-04-01"), by = "quarter")),
       ylim=c(-5, 80),
       index.cond=list(c(3, 1, 2)),
       ylab="Percent (%)",
#       par.strip.text=list(col="white", font=2, lines=1.5),
#       lattice.options = modifyList(lattice.options(), list(skip.boundary.labels = 0)),
#       par.settings=my.settings, col=c("red", "black", "red"), fill=c("red", "black", "red"),
#       key=dat_key,
#       scales = list(x = list(at = sdate, labels = format(sdate, "%b-%y"))), xlab="Date",
       panel = function(x, y, ...) {
         panel.grid(h = -1, v = 0, lwd=1, lty=3, col="grey")
         panel.abline(v=dat$dDate, lwd=1, lty=3, col="grey")
         panel.xyplot(x, y, ...)
         }
         )

As you have upper and lower levels of Zn you may want to look at ?panel.polygon  

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2350



-----Original Message-----
From: R-help [mailto:[hidden email]] On Behalf Of Maria Lathouri via R-help
Sent: Tuesday, 12 September 2017 05:33
To: R-help Mailing List
Subject: [R] show 0 at y axis in xyplot lattice

Dear all
I am trying to make a plot in xyplot lattice by groups. I would like to show "0" in y axis but I don't want to be aligned with the x axis. I want to be a little bit above.
I have tried many options but I don't get what I want. I also tried ylim=c(0, 80) but both 0 and 80 are fully aligned with the x-axis and the upper boundary of the plot, respectively:
xyplot(upper.zn + Zn2 + lower.zn ~ sdate | Location, type="b", as.table=TRUE, data=dat, pch=c(22, 21, 22), lty=c(2, 1, 2), ylim=c(0, 80),
       index.cond=list(c(3, 1, 2)), ylab="Percent (%)", par.strip.text=list(col="white", font=2, lines=1.5),
       lattice.options = modifyList(lattice.options(), list(skip.boundary.labels = 0)),
       par.settings=my.settings, col=c("red", "black", "red"), fill=c("red", "black", "red"),
       key=dat_key, scales = list(x = list(at = sdate, labels = format(sdate, "%b-%y"))), xlab="Date",
       panel = function(x, y, ...) {
         panel.grid(h = -1, v = 0, lwd=1, lty=3, col="grey")              
         panel.abline(v=sdate, lwd=1, lty=3, col="grey")              
         panel.xyplot(x, y, ...)
         }
         )
when I use the following, 80 is a bit lower than the upper boundary of the plot, which is what I want, but 0 is not showing:
xyplot(upper.zn + Zn2 + lower.zn ~ sdate | Location, type="b", as.table=TRUE, data=dat, pch=c(22, 21, 22), lty=c(2, 1, 2),
       index.cond=list(c(3, 1, 2)), ylab="Percent (%)", par.strip.text=list(col="white", font=2, lines=1.5),
       lattice.options = modifyList(lattice.options(), list(skip.boundary.labels = 0)),
       par.settings=my.settings, col=c("red", "black", "red"), fill=c("red", "black", "red"),
       key=dat_key, scales = list(x = list(at = sdate, labels = format(sdate, "%b-%y")), y=list(at=c(0, 20, 40, 60, 80))), xlab="Date",
       panel = function(x, y, ...) {
         panel.grid(h = -1, v = 0, lwd=1, lty=3, col="grey")              
         panel.abline(v=sdate, lwd=1, lty=3, col="grey")              
         panel.xyplot(x, y, ...)
         }
         )I have also attached a reproducible example in case you want to see in more detail my data.
I would very much appreciate any suggestions on this.
Thank you in advance.
Kind regards,Maria

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Σχετ: show 0 at y axis in xyplot lattice

R help mailing list-2
Dear all,
Thank you very much for the help. ylim=c(-5, 80) worked. 
Regarding the reproducible example, I used dput () and saved the file as txt. It is not the first time that I used this way and normally it works. Because when I try to attach a .csv file with the data, most of the time it doesn't go through. 
I will know for the next time. 
Many thanks.
Regards,Maria

    Στις 2:11 π.μ. Τρίτη, 12 Σεπτεμβρίου 2017, ο/η Duncan Mackay <[hidden email]> έγραψε:
 

 Hi Maria

Rule 1 make sure your data is in the right format

dat <- source("G:/1/savedat.txt")
> dat
$value
    Location      Date      Zn2 upper.zn  lower.zn
1    upstream 2016-04-27 29.92477 55.59800 13.912207
2      spill 2016-04-27 12.84040 22.07006  6.964934
3  downstream 2016-04-27 22.49673 41.60901 11.739109
4    upstream 2016-06-28 23.98425 45.60219 10.690640
5      spill 2016-06-28 41.51336 77.99893 20.142426
6  downstream 2016-06-28 15.51232 26.94059  7.044781
7    upstream 2016-08-25 21.73037 40.95852 10.354620
8      spill 2016-08-25 13.42082 22.96901  7.472893
9  downstream 2016-08-25 10.99209 20.17471  5.324318
10  upstream 2016-10-25 20.82462 40.60564  9.602007
11      spill 2016-10-25 14.01283 25.07032  7.830504
12 downstream 2016-10-25 15.67740 30.42278  6.971944
13  upstream 2016-12-21 28.14966 51.79390 14.384139
14      spill 2016-12-21 13.91587 23.94368  8.164688
15 downstream 2016-12-21 13.02749 24.46930  5.826650
16  upstream 2017-02-20 31.16736 55.51858 15.938211
17      spill 2017-02-20 12.47368 22.03830  6.725540
18 downstream 2017-02-20 17.65741 33.23577  8.519928

$visible
[1] TRUE
dat <- dat$value
dat$dDate <- as.Date(as.character(dat$Date))

str(dat)
'data.frame':  18 obs. of  6 variables:
 $ Location: Factor w/ 3 levels "downstream","spill",..: 3 2 1 3 2 1 3 2 1 3 ...
 $ Date    : Factor w/ 6 levels "2016-04-27","2016-06-28",..: 1 1 1 2 2 2 3 3 3 4 ...
 $ Zn2    : num  29.9 12.8 22.5 24 41.5 ...
 $ upper.zn: num  55.6 22.1 41.6 45.6 78 ...
 $ lower.zn: num  13.91 6.96 11.74 10.69 20.14 ...
 $ dDate  : Date, format: "2016-04-27" "2016-04-27" "2016-04-27" "2016-06-28" ...

You code to reproduce the xyplot is not reproducible as it contains user defined objects which you have not included.
Here is something to get you started,
If you want the measurement dates on the x-axis you will need to put the  required dates and format  in the scales argument.
Using par.settings for the symbols an lines will pass those values onto key

xyplot(upper.zn + Zn2 + lower.zn ~ dDate | Location, data=dat,
      type = "b",
      as.table = TRUE,
      par.settings = list(strip.background = list(col = "transparent"),
                          superpose.symbol = list( col=c("red", "black", "red"),
                                              cex = 1,
                                              pch = c(22, 21, 22)),
                          superpose.line = list (col=c("red", "black", "red"),
                                            lty = c(2, 1, 2),
                                            lwd = 1)
                      ),
      auto.key = list(points = TRUE, lines = TRUE),
      scales  = list(x = list(alternating = FALSE,
                                at = seq(from = as.Date("2016-04-01"), to = as.Date("2017-04-01"), by = "quarter"),
                                label = format(seq(from = as.Date("2016-04-01"), to = as.Date("2017-04-01"), by = "quarter"), "%Y %b"),
                                relation    = "same",
                                rot        = 60),
                      y = list(alternating = FALSE,
                                at =  seq(0,80,20),
                                relation    = "same",
                                rot        = 0)
                  ),
#      pch=c(22, 21, 22),
#      lty=c(2, 1, 2),
      xlim = range(seq(from = as.Date("2016-04-01"), to = as.Date("2017-04-01"), by = "quarter")),
      ylim=c(-5, 80),
      index.cond=list(c(3, 1, 2)),
      ylab="Percent (%)",
#      par.strip.text=list(col="white", font=2, lines=1.5),
#      lattice.options = modifyList(lattice.options(), list(skip.boundary.labels = 0)),
#      par.settings=my.settings, col=c("red", "black", "red"), fill=c("red", "black", "red"),
#      key=dat_key,
#      scales = list(x = list(at = sdate, labels = format(sdate, "%b-%y"))), xlab="Date",
      panel = function(x, y, ...) {
        panel.grid(h = -1, v = 0, lwd=1, lty=3, col="grey")
        panel.abline(v=dat$dDate, lwd=1, lty=3, col="grey")
        panel.xyplot(x, y, ...)
        }
        )

As you have upper and lower levels of Zn you may want to look at ?panel.polygon 

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2350



-----Original Message-----
From: R-help [mailto:[hidden email]] On Behalf Of Maria Lathouri via R-help
Sent: Tuesday, 12 September 2017 05:33
To: R-help Mailing List
Subject: [R] show 0 at y axis in xyplot lattice

Dear all
I am trying to make a plot in xyplot lattice by groups. I would like to show "0" in y axis but I don't want to be aligned with the x axis. I want to be a little bit above.
I have tried many options but I don't get what I want. I also tried ylim=c(0, 80) but both 0 and 80 are fully aligned with the x-axis and the upper boundary of the plot, respectively:
xyplot(upper.zn + Zn2 + lower.zn ~ sdate | Location, type="b", as.table=TRUE, data=dat, pch=c(22, 21, 22), lty=c(2, 1, 2), ylim=c(0, 80),
      index.cond=list(c(3, 1, 2)), ylab="Percent (%)", par.strip.text=list(col="white", font=2, lines=1.5),
      lattice.options = modifyList(lattice.options(), list(skip.boundary.labels = 0)),
      par.settings=my.settings, col=c("red", "black", "red"), fill=c("red", "black", "red"),
      key=dat_key, scales = list(x = list(at = sdate, labels = format(sdate, "%b-%y"))), xlab="Date",
      panel = function(x, y, ...) {
        panel.grid(h = -1, v = 0, lwd=1, lty=3, col="grey")             
        panel.abline(v=sdate, lwd=1, lty=3, col="grey")             
        panel.xyplot(x, y, ...)
        }
        )
when I use the following, 80 is a bit lower than the upper boundary of the plot, which is what I want, but 0 is not showing:
xyplot(upper.zn + Zn2 + lower.zn ~ sdate | Location, type="b", as.table=TRUE, data=dat, pch=c(22, 21, 22), lty=c(2, 1, 2),
      index.cond=list(c(3, 1, 2)), ylab="Percent (%)", par.strip.text=list(col="white", font=2, lines=1.5),
      lattice.options = modifyList(lattice.options(), list(skip.boundary.labels = 0)),
      par.settings=my.settings, col=c("red", "black", "red"), fill=c("red", "black", "red"),
      key=dat_key, scales = list(x = list(at = sdate, labels = format(sdate, "%b-%y")), y=list(at=c(0, 20, 40, 60, 80))), xlab="Date",
      panel = function(x, y, ...) {
        panel.grid(h = -1, v = 0, lwd=1, lty=3, col="grey")             
        panel.abline(v=sdate, lwd=1, lty=3, col="grey")             
        panel.xyplot(x, y, ...)
        }
        )I have also attached a reproducible example in case you want to see in more detail my data.
I would very much appreciate any suggestions on this.
Thank you in advance.
Kind regards,Maria


   
        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Σχετ: show 0 at y axis in xyplot lattice

Michael Dewey-3
Dear Maria

The file you attached to your first e-mail did come through but I think
some people on the list must have missed it.

Michael

On 12/09/2017 12:54, Maria Lathouri via R-help wrote:

> Dear all,
> Thank you very much for the help. ylim=c(-5, 80) worked.
> Regarding the reproducible example, I used dput () and saved the file as txt. It is not the first time that I used this way and normally it works. Because when I try to attach a .csv file with the data, most of the time it doesn't go through.
> I will know for the next time.
> Many thanks.
> Regards,Maria
>
>      Στις 2:11 π.μ. Τρίτη, 12 Σεπτεμβρίου 2017, ο/η Duncan Mackay <[hidden email]> έγραψε:
>  
>
>   Hi Maria
>
> Rule 1 make sure your data is in the right format
>
> dat <- source("G:/1/savedat.txt")
>> dat
> $value
>      Location      Date      Zn2 upper.zn  lower.zn
> 1    upstream 2016-04-27 29.92477 55.59800 13.912207
> 2      spill 2016-04-27 12.84040 22.07006  6.964934
> 3  downstream 2016-04-27 22.49673 41.60901 11.739109
> 4    upstream 2016-06-28 23.98425 45.60219 10.690640
> 5      spill 2016-06-28 41.51336 77.99893 20.142426
> 6  downstream 2016-06-28 15.51232 26.94059  7.044781
> 7    upstream 2016-08-25 21.73037 40.95852 10.354620
> 8      spill 2016-08-25 13.42082 22.96901  7.472893
> 9  downstream 2016-08-25 10.99209 20.17471  5.324318
> 10  upstream 2016-10-25 20.82462 40.60564  9.602007
> 11      spill 2016-10-25 14.01283 25.07032  7.830504
> 12 downstream 2016-10-25 15.67740 30.42278  6.971944
> 13  upstream 2016-12-21 28.14966 51.79390 14.384139
> 14      spill 2016-12-21 13.91587 23.94368  8.164688
> 15 downstream 2016-12-21 13.02749 24.46930  5.826650
> 16  upstream 2017-02-20 31.16736 55.51858 15.938211
> 17      spill 2017-02-20 12.47368 22.03830  6.725540
> 18 downstream 2017-02-20 17.65741 33.23577  8.519928
>
> $visible
> [1] TRUE
> dat <- dat$value
> dat$dDate <- as.Date(as.character(dat$Date))
>
> str(dat)
> 'data.frame':  18 obs. of  6 variables:
>   $ Location: Factor w/ 3 levels "downstream","spill",..: 3 2 1 3 2 1 3 2 1 3 ...
>   $ Date    : Factor w/ 6 levels "2016-04-27","2016-06-28",..: 1 1 1 2 2 2 3 3 3 4 ...
>   $ Zn2    : num  29.9 12.8 22.5 24 41.5 ...
>   $ upper.zn: num  55.6 22.1 41.6 45.6 78 ...
>   $ lower.zn: num  13.91 6.96 11.74 10.69 20.14 ...
>   $ dDate  : Date, format: "2016-04-27" "2016-04-27" "2016-04-27" "2016-06-28" ...
>
> You code to reproduce the xyplot is not reproducible as it contains user defined objects which you have not included.
> Here is something to get you started,
> If you want the measurement dates on the x-axis you will need to put the  required dates and format  in the scales argument.
> Using par.settings for the symbols an lines will pass those values onto key
>
> xyplot(upper.zn + Zn2 + lower.zn ~ dDate | Location, data=dat,
>        type = "b",
>        as.table = TRUE,
>        par.settings = list(strip.background = list(col = "transparent"),
>                            superpose.symbol = list( col=c("red", "black", "red"),
>                                                cex = 1,
>                                                pch = c(22, 21, 22)),
>                            superpose.line = list (col=c("red", "black", "red"),
>                                              lty = c(2, 1, 2),
>                                              lwd = 1)
>                        ),
>        auto.key = list(points = TRUE, lines = TRUE),
>        scales  = list(x = list(alternating = FALSE,
>                                  at = seq(from = as.Date("2016-04-01"), to = as.Date("2017-04-01"), by = "quarter"),
>                                  label = format(seq(from = as.Date("2016-04-01"), to = as.Date("2017-04-01"), by = "quarter"), "%Y %b"),
>                                  relation    = "same",
>                                  rot        = 60),
>                        y = list(alternating = FALSE,
>                                  at =  seq(0,80,20),
>                                  relation    = "same",
>                                  rot        = 0)
>                    ),
> #      pch=c(22, 21, 22),
> #      lty=c(2, 1, 2),
>        xlim = range(seq(from = as.Date("2016-04-01"), to = as.Date("2017-04-01"), by = "quarter")),
>        ylim=c(-5, 80),
>        index.cond=list(c(3, 1, 2)),
>        ylab="Percent (%)",
> #      par.strip.text=list(col="white", font=2, lines=1.5),
> #      lattice.options = modifyList(lattice.options(), list(skip.boundary.labels = 0)),
> #      par.settings=my.settings, col=c("red", "black", "red"), fill=c("red", "black", "red"),
> #      key=dat_key,
> #      scales = list(x = list(at = sdate, labels = format(sdate, "%b-%y"))), xlab="Date",
>        panel = function(x, y, ...) {
>          panel.grid(h = -1, v = 0, lwd=1, lty=3, col="grey")
>          panel.abline(v=dat$dDate, lwd=1, lty=3, col="grey")
>          panel.xyplot(x, y, ...)
>          }
>          )
>
> As you have upper and lower levels of Zn you may want to look at ?panel.polygon
>
> Regards
>
> Duncan
>
> Duncan Mackay
> Department of Agronomy and Soil Science
> University of New England
> Armidale NSW 2350
>
>
>
> -----Original Message-----
> From: R-help [mailto:[hidden email]] On Behalf Of Maria Lathouri via R-help
> Sent: Tuesday, 12 September 2017 05:33
> To: R-help Mailing List
> Subject: [R] show 0 at y axis in xyplot lattice
>
> Dear all
> I am trying to make a plot in xyplot lattice by groups. I would like to show "0" in y axis but I don't want to be aligned with the x axis. I want to be a little bit above.
> I have tried many options but I don't get what I want. I also tried ylim=c(0, 80) but both 0 and 80 are fully aligned with the x-axis and the upper boundary of the plot, respectively:
> xyplot(upper.zn + Zn2 + lower.zn ~ sdate | Location, type="b", as.table=TRUE, data=dat, pch=c(22, 21, 22), lty=c(2, 1, 2), ylim=c(0, 80),
>        index.cond=list(c(3, 1, 2)), ylab="Percent (%)", par.strip.text=list(col="white", font=2, lines=1.5),
>        lattice.options = modifyList(lattice.options(), list(skip.boundary.labels = 0)),
>        par.settings=my.settings, col=c("red", "black", "red"), fill=c("red", "black", "red"),
>        key=dat_key, scales = list(x = list(at = sdate, labels = format(sdate, "%b-%y"))), xlab="Date",
>        panel = function(x, y, ...) {
>          panel.grid(h = -1, v = 0, lwd=1, lty=3, col="grey")
>          panel.abline(v=sdate, lwd=1, lty=3, col="grey")
>          panel.xyplot(x, y, ...)
>          }
>          )
> when I use the following, 80 is a bit lower than the upper boundary of the plot, which is what I want, but 0 is not showing:
> xyplot(upper.zn + Zn2 + lower.zn ~ sdate | Location, type="b", as.table=TRUE, data=dat, pch=c(22, 21, 22), lty=c(2, 1, 2),
>        index.cond=list(c(3, 1, 2)), ylab="Percent (%)", par.strip.text=list(col="white", font=2, lines=1.5),
>        lattice.options = modifyList(lattice.options(), list(skip.boundary.labels = 0)),
>        par.settings=my.settings, col=c("red", "black", "red"), fill=c("red", "black", "red"),
>        key=dat_key, scales = list(x = list(at = sdate, labels = format(sdate, "%b-%y")), y=list(at=c(0, 20, 40, 60, 80))), xlab="Date",
>        panel = function(x, y, ...) {
>          panel.grid(h = -1, v = 0, lwd=1, lty=3, col="grey")
>          panel.abline(v=sdate, lwd=1, lty=3, col="grey")
>          panel.xyplot(x, y, ...)
>          }
>          )I have also attached a reproducible example in case you want to see in more detail my data.
> I would very much appreciate any suggestions on this.
> Thank you in advance.
> Kind regards,Maria
>
>
>    
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.
>
> ---
> This email has been checked for viruses by AVG.
> http://www.avg.com
>

--
Michael
http://www.dewey.myzen.co.uk/home.html

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Σχετ: show 0 at y axis in xyplot lattice

Jeff Newmiller
It contains the output of one call to dput, but several objects were missing and the name of the object provided in the text file was not specified.
--
Sent from my phone. Please excuse my brevity.

On September 12, 2017 10:22:36 AM PDT, Michael Dewey <[hidden email]> wrote:

>Dear Maria
>
>The file you attached to your first e-mail did come through but I think
>
>some people on the list must have missed it.
>
>Michael
>
>On 12/09/2017 12:54, Maria Lathouri via R-help wrote:
>> Dear all,
>> Thank you very much for the help. ylim=c(-5, 80) worked.
>> Regarding the reproducible example, I used dput () and saved the file
>as txt. It is not the first time that I used this way and normally it
>works. Because when I try to attach a .csv file with the data, most of
>the time it doesn't go through.
>> I will know for the next time.
>> Many thanks.
>> Regards,Maria
>>
>>      Στις 2:11 π.μ. Τρίτη, 12 Σεπτεμβρίου 2017, ο/η Duncan Mackay
><[hidden email]> έγραψε:
>>  
>>
>>   Hi Maria
>>
>> Rule 1 make sure your data is in the right format
>>
>> dat <- source("G:/1/savedat.txt")
>>> dat
>> $value
>>      Location      Date      Zn2 upper.zn  lower.zn
>> 1    upstream 2016-04-27 29.92477 55.59800 13.912207
>> 2      spill 2016-04-27 12.84040 22.07006  6.964934
>> 3  downstream 2016-04-27 22.49673 41.60901 11.739109
>> 4    upstream 2016-06-28 23.98425 45.60219 10.690640
>> 5      spill 2016-06-28 41.51336 77.99893 20.142426
>> 6  downstream 2016-06-28 15.51232 26.94059  7.044781
>> 7    upstream 2016-08-25 21.73037 40.95852 10.354620
>> 8      spill 2016-08-25 13.42082 22.96901  7.472893
>> 9  downstream 2016-08-25 10.99209 20.17471  5.324318
>> 10  upstream 2016-10-25 20.82462 40.60564  9.602007
>> 11      spill 2016-10-25 14.01283 25.07032  7.830504
>> 12 downstream 2016-10-25 15.67740 30.42278  6.971944
>> 13  upstream 2016-12-21 28.14966 51.79390 14.384139
>> 14      spill 2016-12-21 13.91587 23.94368  8.164688
>> 15 downstream 2016-12-21 13.02749 24.46930  5.826650
>> 16  upstream 2017-02-20 31.16736 55.51858 15.938211
>> 17      spill 2017-02-20 12.47368 22.03830  6.725540
>> 18 downstream 2017-02-20 17.65741 33.23577  8.519928
>>
>> $visible
>> [1] TRUE
>> dat <- dat$value
>> dat$dDate <- as.Date(as.character(dat$Date))
>>
>> str(dat)
>> 'data.frame':  18 obs. of  6 variables:
>>   $ Location: Factor w/ 3 levels "downstream","spill",..: 3 2 1 3 2 1
>3 2 1 3 ...
>>   $ Date    : Factor w/ 6 levels "2016-04-27","2016-06-28",..: 1 1 1
>2 2 2 3 3 3 4 ...
>>   $ Zn2    : num  29.9 12.8 22.5 24 41.5 ...
>>   $ upper.zn: num  55.6 22.1 41.6 45.6 78 ...
>>   $ lower.zn: num  13.91 6.96 11.74 10.69 20.14 ...
>>   $ dDate  : Date, format: "2016-04-27" "2016-04-27" "2016-04-27"
>"2016-06-28" ...
>>
>> You code to reproduce the xyplot is not reproducible as it contains
>user defined objects which you have not included.
>> Here is something to get you started,
>> If you want the measurement dates on the x-axis you will need to put
>the  required dates and format  in the scales argument.
>> Using par.settings for the symbols an lines will pass those values
>onto key
>>
>> xyplot(upper.zn + Zn2 + lower.zn ~ dDate | Location, data=dat,
>>        type = "b",
>>        as.table = TRUE,
>>        par.settings = list(strip.background = list(col =
>"transparent"),
>>                            superpose.symbol = list( col=c("red",
>"black", "red"),
>>                                                cex = 1,
>>                                                pch = c(22, 21, 22)),
>>                            superpose.line = list (col=c("red",
>"black", "red"),
>>                                              lty = c(2, 1, 2),
>>                                              lwd = 1)
>>                        ),
>>        auto.key = list(points = TRUE, lines = TRUE),
>>        scales  = list(x = list(alternating = FALSE,
>>                                  at = seq(from =
>as.Date("2016-04-01"), to = as.Date("2017-04-01"), by = "quarter"),
>>                                  label = format(seq(from =
>as.Date("2016-04-01"), to = as.Date("2017-04-01"), by = "quarter"), "%Y
>%b"),
>>                                  relation    = "same",
>>                                  rot        = 60),
>>                        y = list(alternating = FALSE,
>>                                  at =  seq(0,80,20),
>>                                  relation    = "same",
>>                                  rot        = 0)
>>                    ),
>> #      pch=c(22, 21, 22),
>> #      lty=c(2, 1, 2),
>>        xlim = range(seq(from = as.Date("2016-04-01"), to =
>as.Date("2017-04-01"), by = "quarter")),
>>        ylim=c(-5, 80),
>>        index.cond=list(c(3, 1, 2)),
>>        ylab="Percent (%)",
>> #      par.strip.text=list(col="white", font=2, lines=1.5),
>> #      lattice.options = modifyList(lattice.options(),
>list(skip.boundary.labels = 0)),
>> #      par.settings=my.settings, col=c("red", "black", "red"),
>fill=c("red", "black", "red"),
>> #      key=dat_key,
>> #      scales = list(x = list(at = sdate, labels = format(sdate,
>"%b-%y"))), xlab="Date",
>>        panel = function(x, y, ...) {
>>          panel.grid(h = -1, v = 0, lwd=1, lty=3, col="grey")
>>          panel.abline(v=dat$dDate, lwd=1, lty=3, col="grey")
>>          panel.xyplot(x, y, ...)
>>          }
>>          )
>>
>> As you have upper and lower levels of Zn you may want to look at
>?panel.polygon
>>
>> Regards
>>
>> Duncan
>>
>> Duncan Mackay
>> Department of Agronomy and Soil Science
>> University of New England
>> Armidale NSW 2350
>>
>>
>>
>> -----Original Message-----
>> From: R-help [mailto:[hidden email]] On Behalf Of Maria
>Lathouri via R-help
>> Sent: Tuesday, 12 September 2017 05:33
>> To: R-help Mailing List
>> Subject: [R] show 0 at y axis in xyplot lattice
>>
>> Dear all
>> I am trying to make a plot in xyplot lattice by groups. I would like
>to show "0" in y axis but I don't want to be aligned with the x axis. I
>want to be a little bit above.
>> I have tried many options but I don't get what I want. I also tried
>ylim=c(0, 80) but both 0 and 80 are fully aligned with the x-axis and
>the upper boundary of the plot, respectively:
>> xyplot(upper.zn + Zn2 + lower.zn ~ sdate | Location, type="b",
>as.table=TRUE, data=dat, pch=c(22, 21, 22), lty=c(2, 1, 2), ylim=c(0,
>80),
>>        index.cond=list(c(3, 1, 2)), ylab="Percent (%)",
>par.strip.text=list(col="white", font=2, lines=1.5),
>>        lattice.options = modifyList(lattice.options(),
>list(skip.boundary.labels = 0)),
>>        par.settings=my.settings, col=c("red", "black", "red"),
>fill=c("red", "black", "red"),
>>        key=dat_key, scales = list(x = list(at = sdate, labels =
>format(sdate, "%b-%y"))), xlab="Date",
>>        panel = function(x, y, ...) {
>>          panel.grid(h = -1, v = 0, lwd=1, lty=3, col="grey")
>>          panel.abline(v=sdate, lwd=1, lty=3, col="grey")
>>          panel.xyplot(x, y, ...)
>>          }
>>          )
>> when I use the following, 80 is a bit lower than the upper boundary
>of the plot, which is what I want, but 0 is not showing:
>> xyplot(upper.zn + Zn2 + lower.zn ~ sdate | Location, type="b",
>as.table=TRUE, data=dat, pch=c(22, 21, 22), lty=c(2, 1, 2),
>>        index.cond=list(c(3, 1, 2)), ylab="Percent (%)",
>par.strip.text=list(col="white", font=2, lines=1.5),
>>        lattice.options = modifyList(lattice.options(),
>list(skip.boundary.labels = 0)),
>>        par.settings=my.settings, col=c("red", "black", "red"),
>fill=c("red", "black", "red"),
>>        key=dat_key, scales = list(x = list(at = sdate, labels =
>format(sdate, "%b-%y")), y=list(at=c(0, 20, 40, 60, 80))), xlab="Date",
>>        panel = function(x, y, ...) {
>>          panel.grid(h = -1, v = 0, lwd=1, lty=3, col="grey")
>>          panel.abline(v=sdate, lwd=1, lty=3, col="grey")
>>          panel.xyplot(x, y, ...)
>>          }
>>          )I have also attached a reproducible example in case you
>want to see in more detail my data.
>> I would very much appreciate any suggestions on this.
>> Thank you in advance.
>> Kind regards,Maria
>>
>>
>>    
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> [hidden email] 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.
>>
>> ---
>> This email has been checked for viruses by AVG.
>> http://www.avg.com
>>
>
>--
>Michael
>http://www.dewey.myzen.co.uk/home.html
>
>______________________________________________
>[hidden email] 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.

______________________________________________
[hidden email] 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.