adding a line across plots in xy plot with panel.abline

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

adding a line across plots in xy plot with panel.abline

R help mailing list-2
Dear all,

I want to draw a line at DI=1 across all four graphs in the xy plot, I have used panel.abline, but I failed to do so, does any one has an idea of what has went wrong?

structure(list(Date = structure(c(6L, 7L, 2L, 4L, 13L, 17L, 5L,
12L, 4L, 11L, 14L, 9L, 7L, 2L, 4L, 13L, 10L, 17L, 5L, 12L, 8L,
4L, 11L, 14L, 9L, 16L, 15L, 3L, 10L, 1L, 17L, 5L, 12L, 8L, 4L,
11L, 14L, 12L, 8L, 4L, 11L, 14L), .Label = c("1/10", "1/11",
"11/11", "12/11", "13/10", "19/9", "2/10", "2/11", "20/9", "23/9",
"26/11", "29/10", "29/11", "30/11", "31/10", "4/10", "6/10"), class = "factor"),
    Year = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L,
    2L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L,
    1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
    2L, 2L), .Label = c("Y2002", "Y2014"), class = "factor"),
    Station = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
    1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
    3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L,
    4L, 4L, 4L), .Label = c("E", "F", "H", "I"), class = "factor"),
    DI = c(13.4, 7, 12.6, 12.6, 5.2, 2.2, 1, 1, 1.2, 0.8, 2.3,
    3.8, 5.4, 4.6, 5, 3.2, 3.1, 8.7, 2.1, 2.7, 4.9, 4, 2.2, 5.3,
    5.6, 4.8, 4, 8.6, 1.9, 2.9, 5.9, 2.6, 8.9, 4, 13.5, 15.3,
    12.8, 3.4, 4.7, 1.7, 0.9, 1.7), Date1 = structure(c(16697,
    16710, 16740, 16751, 16768, 16714, 16721, 16737, 16751, 16765,
    16769, 16698, 16710, 16740, 16751, 16768, 16701, 16714, 16721,
    16737, 16741, 16751, 16765, 16769, 16698, 16712, 16739, 16750,
    16701, 16709, 16714, 16721, 16737, 16741, 16751, 16765, 16769,
    16737, 16741, 16751, 16765, 16769), class = "Date")), .Names = c("Date",
"Year", "Station", "DI", "Date1"), row.names = c(NA, -42L), class = "data.frame")
Raw$Date1<-as.Date(Raw$Date,"%d/%m")
culr<-ifelse(Raw$Year=="Y2002","Year 2002","Year 2014")
library(lattice)
xyplot(DI~Date1|Station, data=Raw,
        groups = culr,
        par.settings = list(strip.background = list(col = "transparent"),
                            superpose.symbol = list(cex = rep(2, 2),
                                                    col=c("grey","black"),
                                                    pch = rep(16,2))),
        type="p",
        xlab=list("Month",cex=1.5),
        ylab=list("Dispersion index",cex=1.5),  
        index.cond=list(c(1,2,3,4)),
        auto.key = T,
        layout=c(4,1),
        panel=function(Date1,DI){
        panel.labline(h=1,lty=2,lwd=3)
        })

Many thanks.

Regards,
Christine

 

______________________________________________
[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: adding a line across plots in xy plot with panel.abline

Bert Gunter-2
You misspelled panel.abline as panel.labline in your code you included
here. If that's the real code, that's why.

-- Bert



Bert Gunter

"Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom."
   -- Clifford Stoll


On Sun, Sep 13, 2015 at 8:43 PM, Christine Lee via R-help
<[hidden email]> wrote:

> Dear all,
>
> I want to draw a line at DI=1 across all four graphs in the xy plot, I have used panel.abline, but I failed to do so, does any one has an idea of what has went wrong?
>
> structure(list(Date = structure(c(6L, 7L, 2L, 4L, 13L, 17L, 5L,
> 12L, 4L, 11L, 14L, 9L, 7L, 2L, 4L, 13L, 10L, 17L, 5L, 12L, 8L,
> 4L, 11L, 14L, 9L, 16L, 15L, 3L, 10L, 1L, 17L, 5L, 12L, 8L, 4L,
> 11L, 14L, 12L, 8L, 4L, 11L, 14L), .Label = c("1/10", "1/11",
> "11/11", "12/11", "13/10", "19/9", "2/10", "2/11", "20/9", "23/9",
> "26/11", "29/10", "29/11", "30/11", "31/10", "4/10", "6/10"), class = "factor"),
>     Year = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L,
>     2L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L,
>     1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
>     2L, 2L), .Label = c("Y2002", "Y2014"), class = "factor"),
>     Station = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
>     1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
>     3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L,
>     4L, 4L, 4L), .Label = c("E", "F", "H", "I"), class = "factor"),
>     DI = c(13.4, 7, 12.6, 12.6, 5.2, 2.2, 1, 1, 1.2, 0.8, 2.3,
>     3.8, 5.4, 4.6, 5, 3.2, 3.1, 8.7, 2.1, 2.7, 4.9, 4, 2.2, 5.3,
>     5.6, 4.8, 4, 8.6, 1.9, 2.9, 5.9, 2.6, 8.9, 4, 13.5, 15.3,
>     12.8, 3.4, 4.7, 1.7, 0.9, 1.7), Date1 = structure(c(16697,
>     16710, 16740, 16751, 16768, 16714, 16721, 16737, 16751, 16765,
>     16769, 16698, 16710, 16740, 16751, 16768, 16701, 16714, 16721,
>     16737, 16741, 16751, 16765, 16769, 16698, 16712, 16739, 16750,
>     16701, 16709, 16714, 16721, 16737, 16741, 16751, 16765, 16769,
>     16737, 16741, 16751, 16765, 16769), class = "Date")), .Names = c("Date",
> "Year", "Station", "DI", "Date1"), row.names = c(NA, -42L), class = "data.frame")
> Raw$Date1<-as.Date(Raw$Date,"%d/%m")
> culr<-ifelse(Raw$Year=="Y2002","Year 2002","Year 2014")
> library(lattice)
> xyplot(DI~Date1|Station, data=Raw,
>         groups = culr,
>         par.settings = list(strip.background = list(col = "transparent"),
>                             superpose.symbol = list(cex = rep(2, 2),
>                                                     col=c("grey","black"),
>                                                     pch = rep(16,2))),
>         type="p",
>         xlab=list("Month",cex=1.5),
>         ylab=list("Dispersion index",cex=1.5),
>         index.cond=list(c(1,2,3,4)),
>         auto.key = T,
>         layout=c(4,1),
>         panel=function(Date1,DI){
>         panel.labline(h=1,lty=2,lwd=3)
>         })
>
> Many thanks.
>
> Regards,
> Christine
>
>
>
> ______________________________________________
> [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: adding a line across plots in xy plot with panel.abline

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

As Bert has intimated there was a misspelling in panel.abline

To get points as well you need the appropriate arguments for a panel
function otherwise you would only get a line.
You only had a function for  a line in panel function so adding panel.xyplot
will give you points as well.


xyplot(DI~Date1|Station, data=Raw,
        groups = culr,
        par.settings = list(strip.background = list(col = "transparent"),
                            superpose.symbol = list(cex = rep(2, 2),
                                                    col=c("grey","black"),
                                                    pch = rep(16,2))),
        type="p",
        xlab=list("Month",cex=1.5),
        ylab=list("Dispersion index",cex=1.5),
        index.cond=list(c(1,2,3,4)),
        auto.key = T,
        layout=c(4,1),
        panel = function(x, y, ...){
       
          panel.xyplot(x,y, ...)
          panel.abline(h=1,lty=2,lwd=3)
        }

 )

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: [hidden email]

-----Original Message-----
From: R-help [mailto:[hidden email]] On Behalf Of Christine
Lee via R-help
Sent: Monday, 14 September 2015 13:43
To: [hidden email]
Subject: [R] adding a line across plots in xy plot with panel.abline

Dear all,

I want to draw a line at DI=1 across all four graphs in the xy plot, I have
used panel.abline, but I failed to do so, does any one has an idea of what
has went wrong?

structure(list(Date = structure(c(6L, 7L, 2L, 4L, 13L, 17L, 5L,
12L, 4L, 11L, 14L, 9L, 7L, 2L, 4L, 13L, 10L, 17L, 5L, 12L, 8L,
4L, 11L, 14L, 9L, 16L, 15L, 3L, 10L, 1L, 17L, 5L, 12L, 8L, 4L,
11L, 14L, 12L, 8L, 4L, 11L, 14L), .Label = c("1/10", "1/11",
"11/11", "12/11", "13/10", "19/9", "2/10", "2/11", "20/9", "23/9",
"26/11", "29/10", "29/11", "30/11", "31/10", "4/10", "6/10"), class =
"factor"),
    Year = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L,
    2L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L,
    1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
    2L, 2L), .Label = c("Y2002", "Y2014"), class = "factor"),
    Station = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
    1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
    3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L,
    4L, 4L, 4L), .Label = c("E", "F", "H", "I"), class = "factor"),
    DI = c(13.4, 7, 12.6, 12.6, 5.2, 2.2, 1, 1, 1.2, 0.8, 2.3,
    3.8, 5.4, 4.6, 5, 3.2, 3.1, 8.7, 2.1, 2.7, 4.9, 4, 2.2, 5.3,
    5.6, 4.8, 4, 8.6, 1.9, 2.9, 5.9, 2.6, 8.9, 4, 13.5, 15.3,
    12.8, 3.4, 4.7, 1.7, 0.9, 1.7), Date1 = structure(c(16697,
    16710, 16740, 16751, 16768, 16714, 16721, 16737, 16751, 16765,
    16769, 16698, 16710, 16740, 16751, 16768, 16701, 16714, 16721,
    16737, 16741, 16751, 16765, 16769, 16698, 16712, 16739, 16750,
    16701, 16709, 16714, 16721, 16737, 16741, 16751, 16765, 16769,
    16737, 16741, 16751, 16765, 16769), class = "Date")), .Names = c("Date",

"Year", "Station", "DI", "Date1"), row.names = c(NA, -42L), class =
"data.frame")
Raw$Date1<-as.Date(Raw$Date,"%d/%m")
culr<-ifelse(Raw$Year=="Y2002","Year 2002","Year 2014")
library(lattice)
xyplot(DI~Date1|Station, data=Raw,
        groups = culr,
        par.settings = list(strip.background = list(col = "transparent"),
                            superpose.symbol = list(cex = rep(2, 2),
                                                    col=c("grey","black"),
                                                    pch = rep(16,2))),
        type="p",
        xlab=list("Month",cex=1.5),
        ylab=list("Dispersion index",cex=1.5),  
        index.cond=list(c(1,2,3,4)),
        auto.key = T,
        layout=c(4,1),
        panel=function(Date1,DI){
        panel.labline(h=1,lty=2,lwd=3)
        })

Many thanks.

Regards,
Christine

 

______________________________________________
[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
|

回覆︰ adding a line across plots in xy plot with panel.abline

R help mailing list-2
Thanks, Duncan, I am confused by the function(x,y, ...) and panel.xyplot(x,y,...).  Is this a must to put in "..."? I knew this may be a stupid question.  I am sorry. Christine


     Duncan Mackay <[hidden email]> 於 2015年09月14日 (週一) 3:56 PM 寫道﹕
   

 Hi

As Bert has intimated there was a misspelling in panel.abline

To get points as well you need the appropriate arguments for a panel
function otherwise you would only get a line.
You only had a function for  a line in panel function so adding panel.xyplot
will give you points as well.


xyplot(DI~Date1|Station, data=Raw,
        groups = culr,
        par.settings = list(strip.background = list(col = "transparent"),
                            superpose.symbol = list(cex = rep(2, 2),
                                                    col=c("grey","black"),
                                                    pch = rep(16,2))),
        type="p",
        xlab=list("Month",cex=1.5),
        ylab=list("Dispersion index",cex=1.5),
        index.cond=list(c(1,2,3,4)),
        auto.key = T,
        layout=c(4,1),
        panel = function(x, y, ...){
       
          panel.xyplot(x,y, ...)
          panel.abline(h=1,lty=2,lwd=3)
        }

 )

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: [hidden email]

-----Original Message-----
From: R-help [mailto:[hidden email]] On Behalf Of Christine
Lee via R-help
Sent: Monday, 14 September 2015 13:43
To: [hidden email]
Subject: [R] adding a line across plots in xy plot with panel.abline

Dear all,

I want to draw a line at DI=1 across all four graphs in the xy plot, I have
used panel.abline, but I failed to do so, does any one has an idea of what
has went wrong?

structure(list(Date = structure(c(6L, 7L, 2L, 4L, 13L, 17L, 5L,
12L, 4L, 11L, 14L, 9L, 7L, 2L, 4L, 13L, 10L, 17L, 5L, 12L, 8L,
4L, 11L, 14L, 9L, 16L, 15L, 3L, 10L, 1L, 17L, 5L, 12L, 8L, 4L,
11L, 14L, 12L, 8L, 4L, 11L, 14L), .Label = c("1/10", "1/11",
"11/11", "12/11", "13/10", "19/9", "2/10", "2/11", "20/9", "23/9",
"26/11", "29/10", "29/11", "30/11", "31/10", "4/10", "6/10"), class =
"factor"),
    Year = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L,
    2L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L,
    1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
    2L, 2L), .Label = c("Y2002", "Y2014"), class = "factor"),
    Station = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
    1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
    3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L,
    4L, 4L, 4L), .Label = c("E", "F", "H", "I"), class = "factor"),
    DI = c(13.4, 7, 12.6, 12.6, 5.2, 2.2, 1, 1, 1.2, 0.8, 2.3,
    3.8, 5.4, 4.6, 5, 3.2, 3.1, 8.7, 2.1, 2.7, 4.9, 4, 2.2, 5.3,
    5.6, 4.8, 4, 8.6, 1.9, 2.9, 5.9, 2.6, 8.9, 4, 13.5, 15.3,
    12.8, 3.4, 4.7, 1.7, 0.9, 1.7), Date1 = structure(c(16697,
    16710, 16740, 16751, 16768, 16714, 16721, 16737, 16751, 16765,
    16769, 16698, 16710, 16740, 16751, 16768, 16701, 16714, 16721,
    16737, 16741, 16751, 16765, 16769, 16698, 16712, 16739, 16750,
    16701, 16709, 16714, 16721, 16737, 16741, 16751, 16765, 16769,
    16737, 16741, 16751, 16765, 16769), class = "Date")), .Names = c("Date",

"Year", "Station", "DI", "Date1"), row.names = c(NA, -42L), class =
"data.frame")
Raw$Date1<-as.Date(Raw$Date,"%d/%m")
culr<-ifelse(Raw$Year=="Y2002","Year 2002","Year 2014")
library(lattice)
xyplot(DI~Date1|Station, data=Raw,
        groups = culr,
        par.settings = list(strip.background = list(col = "transparent"),
                            superpose.symbol = list(cex = rep(2, 2),
                                                    col=c("grey","black"),
                                                    pch = rep(16,2))),
        type="p",
        xlab=list("Month",cex=1.5),
        ylab=list("Dispersion index",cex=1.5), 
        index.cond=list(c(1,2,3,4)),
        auto.key = T,
        layout=c(4,1),
        panel=function(Date1,DI){
        panel.labline(h=1,lty=2,lwd=3)
        })

Many thanks.

Regards,
Christine

 

______________________________________________
[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: 回覆︰ adding a line across plots in xy plot with panel.abline

Michael Dewey-3
Dear Christine

The point of the ellipsis ... is to pass into the interior function any
other parameters which were supplied to the exterior function. If you
know for sure that there will never, never, never be such additional
parameters then you can leave it out but that is a bit like not using a
seat belt on the basis that you do not plan to have an accident.

On 14/09/2015 10:30, Christine Lee via R-help wrote:

> Thanks, Duncan, I am confused by the function(x,y, ...) and panel.xyplot(x,y,...).  Is this a must to put in "..."? I knew this may be a stupid question.  I am sorry. Christine
>
>
>       Duncan Mackay <[hidden email]> 於 2015年09月14日 (週一) 3:56 PM 寫道﹕
>
>
>   Hi
>
> As Bert has intimated there was a misspelling in panel.abline
>
> To get points as well you need the appropriate arguments for a panel
> function otherwise you would only get a line.
> You only had a function for  a line in panel function so adding panel.xyplot
> will give you points as well.
>
>
> xyplot(DI~Date1|Station, data=Raw,
>          groups = culr,
>          par.settings = list(strip.background = list(col = "transparent"),
>                              superpose.symbol = list(cex = rep(2, 2),
>                                                      col=c("grey","black"),
>                                                      pch = rep(16,2))),
>          type="p",
>          xlab=list("Month",cex=1.5),
>          ylab=list("Dispersion index",cex=1.5),
>          index.cond=list(c(1,2,3,4)),
>          auto.key = T,
>          layout=c(4,1),
>          panel = function(x, y, ...){
>
>            panel.xyplot(x,y, ...)
>            panel.abline(h=1,lty=2,lwd=3)
>          }
>
>   )
>
> Regards
>
> Duncan
>
> Duncan Mackay
> Department of Agronomy and Soil Science
> University of New England
> Armidale NSW 2351
> Email: home: [hidden email]
>
> -----Original Message-----
> From: R-help [mailto:[hidden email]] On Behalf Of Christine
> Lee via R-help
> Sent: Monday, 14 September 2015 13:43
> To: [hidden email]
> Subject: [R] adding a line across plots in xy plot with panel.abline
>
> Dear all,
>
> I want to draw a line at DI=1 across all four graphs in the xy plot, I have
> used panel.abline, but I failed to do so, does any one has an idea of what
> has went wrong?
>
> structure(list(Date = structure(c(6L, 7L, 2L, 4L, 13L, 17L, 5L,
> 12L, 4L, 11L, 14L, 9L, 7L, 2L, 4L, 13L, 10L, 17L, 5L, 12L, 8L,
> 4L, 11L, 14L, 9L, 16L, 15L, 3L, 10L, 1L, 17L, 5L, 12L, 8L, 4L,
> 11L, 14L, 12L, 8L, 4L, 11L, 14L), .Label = c("1/10", "1/11",
> "11/11", "12/11", "13/10", "19/9", "2/10", "2/11", "20/9", "23/9",
> "26/11", "29/10", "29/11", "30/11", "31/10", "4/10", "6/10"), class =
> "factor"),
>      Year = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L,
>      2L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L,
>      1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
>      2L, 2L), .Label = c("Y2002", "Y2014"), class = "factor"),
>      Station = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
>      1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
>      3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L,
>      4L, 4L, 4L), .Label = c("E", "F", "H", "I"), class = "factor"),
>      DI = c(13.4, 7, 12.6, 12.6, 5.2, 2.2, 1, 1, 1.2, 0.8, 2.3,
>      3.8, 5.4, 4.6, 5, 3.2, 3.1, 8.7, 2.1, 2.7, 4.9, 4, 2.2, 5.3,
>      5.6, 4.8, 4, 8.6, 1.9, 2.9, 5.9, 2.6, 8.9, 4, 13.5, 15.3,
>      12.8, 3.4, 4.7, 1.7, 0.9, 1.7), Date1 = structure(c(16697,
>      16710, 16740, 16751, 16768, 16714, 16721, 16737, 16751, 16765,
>      16769, 16698, 16710, 16740, 16751, 16768, 16701, 16714, 16721,
>      16737, 16741, 16751, 16765, 16769, 16698, 16712, 16739, 16750,
>      16701, 16709, 16714, 16721, 16737, 16741, 16751, 16765, 16769,
>      16737, 16741, 16751, 16765, 16769), class = "Date")), .Names = c("Date",
>
> "Year", "Station", "DI", "Date1"), row.names = c(NA, -42L), class =
> "data.frame")
> Raw$Date1<-as.Date(Raw$Date,"%d/%m")
> culr<-ifelse(Raw$Year=="Y2002","Year 2002","Year 2014")
> library(lattice)
> xyplot(DI~Date1|Station, data=Raw,
>          groups = culr,
>          par.settings = list(strip.background = list(col = "transparent"),
>                              superpose.symbol = list(cex = rep(2, 2),
>                                                      col=c("grey","black"),
>                                                      pch = rep(16,2))),
>          type="p",
>          xlab=list("Month",cex=1.5),
>          ylab=list("Dispersion index",cex=1.5),
>          index.cond=list(c(1,2,3,4)),
>          auto.key = T,
>          layout=c(4,1),
>          panel=function(Date1,DI){
>          panel.labline(h=1,lty=2,lwd=3)
>          })
>
> Many thanks.
>
> Regards,
> Christine
>
>
>
> ______________________________________________
> [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.
>

--
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: 回覆︰ adding a line across plots in xy plot with panel.abline

Bert Gunter-2
Christine:

You need to spend some time with an R tutorial ("An Intro to R" ships
with R, but there are many on the web) where function arguments are
explained more fully. That should go a long way to clearing up your
"stupidity."

Cheers,
Bert


Bert Gunter

"Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom."
   -- Clifford Stoll


On Mon, Sep 14, 2015 at 6:27 AM, Michael Dewey <[hidden email]> wrote:

> Dear Christine
>
> The point of the ellipsis ... is to pass into the interior function any
> other parameters which were supplied to the exterior function. If you know
> for sure that there will never, never, never be such additional parameters
> then you can leave it out but that is a bit like not using a seat belt on
> the basis that you do not plan to have an accident.
>
>
> On 14/09/2015 10:30, Christine Lee via R-help wrote:
>>
>> Thanks, Duncan, I am confused by the function(x,y, ...) and
>> panel.xyplot(x,y,...).  Is this a must to put in "..."? I knew this may be a
>> stupid question.  I am sorry. Christine
>>
>>
>>       Duncan Mackay <[hidden email]> 於 2015年09月14日 (週一) 3:56 PM 寫道﹕
>>
>>
>>   Hi
>>
>> As Bert has intimated there was a misspelling in panel.abline
>>
>> To get points as well you need the appropriate arguments for a panel
>> function otherwise you would only get a line.
>> You only had a function for  a line in panel function so adding
>> panel.xyplot
>> will give you points as well.
>>
>>
>> xyplot(DI~Date1|Station, data=Raw,
>>          groups = culr,
>>          par.settings = list(strip.background = list(col = "transparent"),
>>                              superpose.symbol = list(cex = rep(2, 2),
>>
>> col=c("grey","black"),
>>                                                      pch = rep(16,2))),
>>          type="p",
>>          xlab=list("Month",cex=1.5),
>>          ylab=list("Dispersion index",cex=1.5),
>>          index.cond=list(c(1,2,3,4)),
>>          auto.key = T,
>>          layout=c(4,1),
>>          panel = function(x, y, ...){
>>
>>            panel.xyplot(x,y, ...)
>>            panel.abline(h=1,lty=2,lwd=3)
>>          }
>>
>>   )
>>
>> Regards
>>
>> Duncan
>>
>> Duncan Mackay
>> Department of Agronomy and Soil Science
>> University of New England
>> Armidale NSW 2351
>> Email: home: [hidden email]
>>
>> -----Original Message-----
>> From: R-help [mailto:[hidden email]] On Behalf Of Christine
>> Lee via R-help
>> Sent: Monday, 14 September 2015 13:43
>> To: [hidden email]
>> Subject: [R] adding a line across plots in xy plot with panel.abline
>>
>> Dear all,
>>
>> I want to draw a line at DI=1 across all four graphs in the xy plot, I
>> have
>> used panel.abline, but I failed to do so, does any one has an idea of what
>> has went wrong?
>>
>> structure(list(Date = structure(c(6L, 7L, 2L, 4L, 13L, 17L, 5L,
>> 12L, 4L, 11L, 14L, 9L, 7L, 2L, 4L, 13L, 10L, 17L, 5L, 12L, 8L,
>> 4L, 11L, 14L, 9L, 16L, 15L, 3L, 10L, 1L, 17L, 5L, 12L, 8L, 4L,
>> 11L, 14L, 12L, 8L, 4L, 11L, 14L), .Label = c("1/10", "1/11",
>> "11/11", "12/11", "13/10", "19/9", "2/10", "2/11", "20/9", "23/9",
>> "26/11", "29/10", "29/11", "30/11", "31/10", "4/10", "6/10"), class =
>> "factor"),
>>      Year = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L,
>>      2L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L,
>>      1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
>>      2L, 2L), .Label = c("Y2002", "Y2014"), class = "factor"),
>>      Station = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
>>      1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
>>      3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L,
>>      4L, 4L, 4L), .Label = c("E", "F", "H", "I"), class = "factor"),
>>      DI = c(13.4, 7, 12.6, 12.6, 5.2, 2.2, 1, 1, 1.2, 0.8, 2.3,
>>      3.8, 5.4, 4.6, 5, 3.2, 3.1, 8.7, 2.1, 2.7, 4.9, 4, 2.2, 5.3,
>>      5.6, 4.8, 4, 8.6, 1.9, 2.9, 5.9, 2.6, 8.9, 4, 13.5, 15.3,
>>      12.8, 3.4, 4.7, 1.7, 0.9, 1.7), Date1 = structure(c(16697,
>>      16710, 16740, 16751, 16768, 16714, 16721, 16737, 16751, 16765,
>>      16769, 16698, 16710, 16740, 16751, 16768, 16701, 16714, 16721,
>>      16737, 16741, 16751, 16765, 16769, 16698, 16712, 16739, 16750,
>>      16701, 16709, 16714, 16721, 16737, 16741, 16751, 16765, 16769,
>>      16737, 16741, 16751, 16765, 16769), class = "Date")), .Names =
>> c("Date",
>>
>> "Year", "Station", "DI", "Date1"), row.names = c(NA, -42L), class =
>> "data.frame")
>> Raw$Date1<-as.Date(Raw$Date,"%d/%m")
>> culr<-ifelse(Raw$Year=="Y2002","Year 2002","Year 2014")
>> library(lattice)
>> xyplot(DI~Date1|Station, data=Raw,
>>          groups = culr,
>>          par.settings = list(strip.background = list(col = "transparent"),
>>                              superpose.symbol = list(cex = rep(2, 2),
>>
>> col=c("grey","black"),
>>                                                      pch = rep(16,2))),
>>          type="p",
>>          xlab=list("Month",cex=1.5),
>>          ylab=list("Dispersion index",cex=1.5),
>>          index.cond=list(c(1,2,3,4)),
>>          auto.key = T,
>>          layout=c(4,1),
>>          panel=function(Date1,DI){
>>          panel.labline(h=1,lty=2,lwd=3)
>>          })
>>
>> Many thanks.
>>
>> Regards,
>> Christine
>>
>>
>>
>> ______________________________________________
>> [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.
>>
>
> --
> 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.
Reply | Threaded
Open this post in threaded view
|

Re: 回覆︰ adding a line across plots in xy plot with panel.abline

Duncan Mackay-4
In reply to this post by R help mailing list-2
forgot to send to list

 

From: Duncan Mackay [mailto:[hidden email]]
Sent: Tuesday, 15 September 2015 01:47
To: 'Christine Lee'
Subject: RE: 回覆︰ [R] adding a line across plots in xy plot with panel.abline

 

Hi

 

If your panel function was like this (just adding to plot the points with the argument panel.xyplot  

 

        panel= function(Date1,DI){

                 panel.xyplot(Date1,DI)

                 panel.abline(h=1,lty=2,lwd=3)

        }

 

and this would cause an error see ? panel.xyplot

you can test it by replacing the lines  and see what happens

 

Now with the panel function like this

        panel = function(x, y, ...){

       

          panel.xyplot(x,y, ...)

          panel.abline(h=1,lty=2,lwd=3)

        }

 

it will “carry” the parameters in par.settings to the functions within the panel function.

One advantage of this is that you do not have to finish panel.xplot with what you want eg

 

panel.xyplot(x,y,  pch = 16, col = c(1,2), cex = 2)

 

In some contexts you can get away with just

   panel = function(...){

       

but in this case there is an error message in each panel saying y cannot be found

 

I cannot think of a good example at the moment run

 

demo(lattice::intervals )

and look at the code output

 

see also ? panel.superpose

 

 

Regards

 

Duncan

 

 

 

From: Christine Lee [mailto:[hidden email]]
Sent: Monday, 14 September 2015 19:30
To: Duncan Mackay; R
Subject: 回覆︰ [R] adding a line across plots in xy plot with panel.abline

 

Thanks, Duncan,

 

I am confused by the function(x,y, ...) and panel.xyplot(x,y,...).  Is this a must to put in "..."? I knew this may be a stupid question.  I am sorry.

 

Christine

 

 

Duncan Mackay <[hidden email]> 於 2015年09月14日 (週一) 3:56 PM 寫道﹕

 

Hi

As Bert has intimated there was a misspelling in panel.abline

To get points as well you need the appropriate arguments for a panel
function otherwise you would only get a line.
You only had a function for  a line in panel function so adding panel.xyplot
will give you points as well.


xyplot(DI~Date1|Station, data=Raw,
        groups = culr,
        par.settings = list(strip.background = list(col = "transparent"),
                            superpose.symbol = list(cex = rep(2, 2),
                                                    col=c("grey","black"),
                                                    pch = rep(16,2))),
        type="p",
        xlab=list("Month",cex=1.5),
        ylab=list("Dispersion index",cex=1.5),
        index.cond=list(c(1,2,3,4)),
        auto.key = T,
        layout=c(4,1),
        panel = function(x, y, ...){
       
          panel.xyplot(x,y, ...)
          panel.abline(h=1,lty=2,lwd=3)
        }

)

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: [hidden email]


-----Original Message-----
From: R-help [mailto:[hidden email]] On Behalf Of Christine
Lee via R-help
Sent: Monday, 14 September 2015 13:43
To: [hidden email]
Subject: [R] adding a line across plots in xy plot with panel.abline

Dear all,

I want to draw a line at DI=1 across all four graphs in the xy plot, I have
used panel.abline, but I failed to do so, does any one has an idea of what
has went wrong?

structure(list(Date = structure(c(6L, 7L, 2L, 4L, 13L, 17L, 5L,
12L, 4L, 11L, 14L, 9L, 7L, 2L, 4L, 13L, 10L, 17L, 5L, 12L, 8L,
4L, 11L, 14L, 9L, 16L, 15L, 3L, 10L, 1L, 17L, 5L, 12L, 8L, 4L,
11L, 14L, 12L, 8L, 4L, 11L, 14L), .Label = c("1/10", "1/11",
"11/11", "12/11", "13/10", "19/9", "2/10", "2/11", "20/9", "23/9",
"26/11", "29/10", "29/11", "30/11", "31/10", "4/10", "6/10"), class =
"factor"),
    Year = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L,
    2L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L,
    1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
    2L, 2L), .Label = c("Y2002", "Y2014"), class = "factor"),
    Station = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
    1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
    3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L,
    4L, 4L, 4L), .Label = c("E", "F", "H", "I"), class = "factor"),
    DI = c(13.4, 7, 12.6, 12.6, 5.2, 2.2, 1, 1, 1.2, 0.8, 2.3,
    3.8, 5.4, 4.6, 5, 3.2, 3.1, 8.7, 2.1, 2.7, 4.9, 4, 2.2, 5.3,
    5.6, 4.8, 4, 8.6, 1.9, 2.9, 5.9, 2.6, 8.9, 4, 13.5, 15.3,
    12.8, 3.4, 4.7, 1.7, 0.9, 1.7), Date1 = structure(c(16697,
    16710, 16740, 16751, 16768, 16714, 16721, 16737, 16751, 16765,
    16769, 16698, 16710, 16740, 16751, 16768, 16701, 16714, 16721,
    16737, 16741, 16751, 16765, 16769, 16698, 16712, 16739, 16750,
    16701, 16709, 16714, 16721, 16737, 16741, 16751, 16765, 16769,
    16737, 16741, 16751, 16765, 16769), class = "Date")), .Names = c("Date",

"Year", "Station", "DI", "Date1"), row.names = c(NA, -42L), class =
"data.frame")
Raw$Date1<-as.Date(Raw$Date,"%d/%m")
culr<-ifelse(Raw$Year=="Y2002","Year 2002","Year 2014")
library(lattice)
xyplot(DI~Date1|Station, data=Raw,
        groups = culr,
        par.settings = list(strip.background = list(col = "transparent"),
                            superpose.symbol = list(cex = rep(2, 2),
                                                    col=c("grey","black"),
                                                    pch = rep(16,2))),
        type="p",
        xlab=list("Month",cex=1.5),
        ylab=list("Dispersion index",cex=1.5),  
        index.cond=list(c(1,2,3,4)),
        auto.key = T,
        layout=c(4,1),
        panel=function(Date1,DI){
        panel.labline(h=1,lty=2,lwd=3)
        })

Many thanks.

Regards,
Christine



______________________________________________
[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.