Christine Lee
2015-Sep-14 03:43 UTC
[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
Bert Gunter
2015-Sep-14 06:00 UTC
[R] adding a line across plots in xy plot with panel.abline
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 <r-help at r-project.org> 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 > > > > ______________________________________________ > R-help at 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.
Duncan Mackay
2015-Sep-14 07:56 UTC
[R] adding a line across plots in xy plot with panel.abline
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: mackay at northnet.com.au -----Original Message----- From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Christine Lee via R-help Sent: Monday, 14 September 2015 13:43 To: r-help at r-project.org 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 ______________________________________________ R-help at 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.
Christine Lee
2015-Sep-14 09:30 UTC
[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 <dulcalma at bigpond.com> ? 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: mackay at northnet.com.au -----Original Message----- From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Christine Lee via R-help Sent: Monday, 14 September 2015 13:43 To: r-help at r-project.org 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 ______________________________________________ R-help at 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]]