To whom it may concern,
I have tried to plot some numbers against time with the time on the X-axis shown
as "Jan", "Feb", etc.
I used the following commands:
Raw<-structure(list(Date = structure(c(6L, 7L, 2L, 4L, 12L, 9L, 7L,
2L, 4L, 12L), .Label = c("1/10", "1/11", "11/11",
"12/11", "13/10",
"19/9", "2/10", "2/11", "20/9",
"26/11", "29/10", "29/11", "30/11",
"31/10", "4/10", "6/10"), class =
"factor"), Year = c(2002L,
2002L, 2002L, 2002L, 2002L, 2002L, 2002L, 2002L, 2002L, 2002L
), Station = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L,
2L), .Label = c("E", "F", "H", "I"),
class = "factor"), Abun = c(3.42,
1.33, 3.67, 3.67, 3.92, 2.17, 2.5, 1.67, 6.33, 0.67), Date1 = structure(c(16697,
16710, 16740, 16751, 16768, 16698, 16710, 16740, 16751, 16768
), class = "Date")), .Names = c("Date", "Year",
"Station", "Abun",
"Date1"), row.names = c(NA, 10L), class = "data.frame")
Raw$Date1<-as.Date(Raw$Date,"%d/%m")
xyplot(Abun~Date1|as.factor(Year),Raw,type="p",xlab=list("Month",cex=1.5),ylab=list("Abundance",cex=1.5),cex=2,pch=c(16,16,21),col=c("Black","Grey","Black"),strip=strip.custom(bg='white'),format="%B-%d")
The date format shown on X-axis was just "10-1", "10-15"
I should be grateful if any one could help indicating what has gone wrong?
Regards,
Christine
See inline below. On 18/08/15 16:15, Christine Lee via R-help wrote:> To whom it may concern, > > I have tried to plot some numbers against time with the time on the X-axis > shown as "Jan", "Feb", etc. > > I used the following commands: > Raw<-structure(list(Date = structure(c(6L, 7L, 2L, 4L, 12L, 9L, 7L, > 2L, 4L, 12L), .Label = c("1/10", "1/11", "11/11", "12/11", "13/10", > "19/9", "2/10", "2/11", "20/9", "26/11", "29/10", "29/11", "30/11", > "31/10", "4/10", "6/10"), class = "factor"), Year = c(2002L, > 2002L, 2002L, 2002L, 2002L, 2002L, 2002L, 2002L, 2002L, 2002L > ), Station = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, > 2L), .Label = c("E", "F", "H", "I"), class = "factor"), Abun = c(3.42, > 1.33, 3.67, 3.67, 3.92, 2.17, 2.5, 1.67, 6.33, 0.67), Date1 = structure(c(16697, > 16710, 16740, 16751, 16768, 16698, 16710, 16740, 16751, 16768 > ), class = "Date")), .Names = c("Date", "Year", "Station", "Abun", > "Date1"), row.names = c(NA, 10L), class = "data.frame") > > Raw$Date1<-as.Date(Raw$Date,"%d/%m")What does this accomplish? As far as I can tell Raw$Date1 is the same after doing this replacement as it was before.> xyplot(Abun~Date1|as.factor(Year),Raw,type="p",xlab=list("Month",cex=1.5), > lab=list("Abundance",cex=1.5),cex=2,pch=c(16,16,21),col=c("Black","Grey","Black"), > strip=strip.custom(bg='white'),format="%B-%d") > > The date format shown on X-axis was just "10-1", "10-15"Not what I get.> I should be grateful if any one could help indicating what has gone wrong?No idea. When I try your code, the x-axis labels that I get are "Oct 01", "Oct 15", ..., "Dec 01", which looks pretty much as it should. General advice --- when you are getting unexpected results, try the example in a stripped down "keep it simple" form --- i.e. eliminate most of the bells and whistles in your very complicated call to xyplot(). That might give you a better chance at discerning what is causing things to go wrong for you. cheers, Rolf Turner -- Technical Editor ANZJS Department of Statistics University of Auckland Phone: +64-9-373-7599 ext. 88276
Thanks Mr. Turner,?This puzzles me.? Why do we come out with different axis
labels with the same command?? Is this because of my R version or my
computer??Regards,Christine
Rolf Turner <r.turner at auckland.ac.nz> ? 2015?08?18? (??) 2:02 PM
???
See inline below.
On 18/08/15 16:15, Christine Lee via R-help wrote:> To whom it may concern,
>
> I have tried to plot some numbers against time with the time on the X-axis
> shown as "Jan", "Feb", etc.
>
> I used the following commands:
> Raw<-structure(list(Date = structure(c(6L, 7L, 2L, 4L, 12L, 9L, 7L,
> 2L, 4L, 12L), .Label = c("1/10", "1/11",
"11/11", "12/11", "13/10",
> "19/9", "2/10", "2/11", "20/9",
"26/11", "29/10", "29/11", "30/11",
> "31/10", "4/10", "6/10"), class =
"factor"), Year = c(2002L,
> 2002L, 2002L, 2002L, 2002L, 2002L, 2002L, 2002L, 2002L, 2002L
> ), Station = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L,
> 2L), .Label = c("E", "F", "H",
"I"), class = "factor"), Abun = c(3.42,
> 1.33, 3.67, 3.67, 3.92, 2.17, 2.5, 1.67, 6.33, 0.67), Date1 =
structure(c(16697,
> 16710, 16740, 16751, 16768, 16698, 16710, 16740, 16751, 16768
> ), class = "Date")), .Names = c("Date",
"Year", "Station", "Abun",
> "Date1"), row.names = c(NA, 10L), class = "data.frame")
>
> Raw$Date1<-as.Date(Raw$Date,"%d/%m")
What does this accomplish?? As far as I can tell Raw$Date1 is the same
after doing this replacement as it was before.
>
xyplot(Abun~Date1|as.factor(Year),Raw,type="p",xlab=list("Month",cex=1.5),
>
lab=list("Abundance",cex=1.5),cex=2,pch=c(16,16,21),col=c("Black","Grey","Black"),
> strip=strip.custom(bg='white'),format="%B-%d")
>
> The date format shown on X-axis was just "10-1",
"10-15"
Not what I get.
> I should be grateful if any one could help indicating what has gone wrong?
No idea.? When I try your code, the x-axis labels that I get are
"Oct 01", "Oct 15", ..., "Dec 01", which looks
pretty much as it should.
General advice --- when you are getting unexpected results, try the
example in a stripped down "keep it simple" form --- i.e. eliminate
most
of the bells and whistles in your very complicated call to xyplot().
That might give you a better chance at discerning what is causing things
to go wrong for you.
cheers,
Rolf Turner
--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276
[[alternative HTML version deleted]]
Hi Christine
If somethings go wrong:
1 first check your data
str(Raw)
'data.frame': 10 obs. of 5 variables:
$ Date : Factor w/ 16 levels "1/10","1/11",..: 6 7 2 4 12
9 7 2 4 12
$ Year : int 2002 2002 2002 2002 2002 2002 2002 2002 2002 2002
$ Station: Factor w/ 4 levels
"E","F","H","I": 1 1 1 1 1 2 2 2 2 2
$ Abun : num 3.42 1.33 3.67 3.67 3.92 2.17 2.5 1.67 6.33 0.67
$ Date1 : Date, format: "2015-09-19" "2015-10-02"
"2015-11-01"
"2015-11-12" ...
Raw$Date2 <- as.character(Raw$Date1)
Raw$Date2
[1] "2015-09-19" "2015-10-02" "2015-11-01"
"2015-11-12" "2015-11-29"
"2015-09-20" "2015-10-02" "2015-11-01"
"2015-11-12" "2015-11-29"
Raw$Date2 <- as.Date(Raw$Date2, "%Y-%m-%d")
2 read the help guide again if not done recently ?lattice::xyplot or ?xyplot
3 start with a minimum number of arguments
xyplot(Abun~Date2|as.factor(Year), Raw)
or
xyplot(Abun~Date2, Raw)
if you are still having problems
Dates are hard work in any language as they are not consistent so:
a. use default
b. use your own
This works
xyplot(Abun~Date2|as.factor(Year), Raw,
par.settings = list(stripbackground = "transparent"), #
background
colour controlled here
type="p",
scales = list(x = list(at = sort(c(seq(as.Date(Raw$Date2[1]-4), by
"months", length = 4),
seq(as.Date(Raw$Date2[1]+12), by
= "months", length = 3))),
labels format(sort(c(seq(as.Date(Raw$Date2[1]-4),
by = "months", length = 4),
seq(as.Date(Raw$Date2[1]+12), by = "months", length = 3))),
"%m-%d") ) ),
xlab=list("Month",cex=1.5),
ylab=list("Abundance",cex=1.5),
cex=2,
pch=c(16,16,21),
col=c("Black","Grey","Black")
)
par.settings is confining the parameters set by trellis.par.set() to the
function
to get them
names(trellis.par.get() )
and going further
trellis.par.get()$superpose.symbol
will give you the values for superpose.symbol
Beware: Do not make the labels etc so big that the axis labels are hard to
read. Think of final size
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: Tuesday, 18 August 2015 14:16
To: r-help at r-project.org
Subject: [R] date format in xyplot
To whom it may concern,
I have tried to plot some numbers against time with the time on the X-axis
shown as "Jan", "Feb", etc.
I used the following commands:
Raw<-structure(list(Date = structure(c(6L, 7L, 2L, 4L, 12L, 9L, 7L,
2L, 4L, 12L), .Label = c("1/10", "1/11", "11/11",
"12/11", "13/10",
"19/9", "2/10", "2/11", "20/9",
"26/11", "29/10", "29/11", "30/11",
"31/10", "4/10", "6/10"), class =
"factor"), Year = c(2002L,
2002L, 2002L, 2002L, 2002L, 2002L, 2002L, 2002L, 2002L, 2002L
), Station = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L,
2L), .Label = c("E", "F", "H", "I"),
class = "factor"), Abun = c(3.42,
1.33, 3.67, 3.67, 3.92, 2.17, 2.5, 1.67, 6.33, 0.67), Date1 structure(c(16697,
16710, 16740, 16751, 16768, 16698, 16710, 16740, 16751, 16768
), class = "Date")), .Names = c("Date", "Year",
"Station", "Abun",
"Date1"), row.names = c(NA, 10L), class = "data.frame")
Raw$Date1<-as.Date(Raw$Date,"%d/%m")
xyplot(Abun~Date1|as.factor(Year),Raw,type="p",xlab=list("Month",cex=1.5),yl
ab=list("Abundance",cex=1.5),cex=2,pch=c(16,16,21),col=c("Black","Grey","Bla
ck"),strip=strip.custom(bg='white'),format="%B-%d")
The date format shown on X-axis was just "10-1", "10-15"
I should be grateful if any one could help indicating what has gone wrong?
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.
Hi Christine, I am afraid I cannot help as it 'appears' fine here I get an x-axis witih Oct 01 Oct 15 Nov 15 Dec 01 I don't normally use lattice but the dates seem reasonable to me Do a str(Raw) and check if Date1 is actually a date in your orginal data. It is one here but who knows with R :) John Kane Kingston ON Canada> -----Original Message----- > From: r-help at r-project.org > Sent: Mon, 17 Aug 2015 21:15:39 -0700 > To: r-help at r-project.org > Subject: [R] date format in xyplot > > To whom it may concern, > > I have tried to plot some numbers against time with the time on the > X-axis shown as "Jan", "Feb", etc. > > I used the following commands: > Raw<-structure(list(Date = structure(c(6L, 7L, 2L, 4L, 12L, 9L, 7L, > 2L, 4L, 12L), .Label = c("1/10", "1/11", "11/11", "12/11", "13/10", > "19/9", "2/10", "2/11", "20/9", "26/11", "29/10", "29/11", "30/11", > "31/10", "4/10", "6/10"), class = "factor"), Year = c(2002L, > 2002L, 2002L, 2002L, 2002L, 2002L, 2002L, 2002L, 2002L, 2002L > ), Station = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, > 2L), .Label = c("E", "F", "H", "I"), class = "factor"), Abun = c(3.42, > 1.33, 3.67, 3.67, 3.92, 2.17, 2.5, 1.67, 6.33, 0.67), Date1 > structure(c(16697, > 16710, 16740, 16751, 16768, 16698, 16710, 16740, 16751, 16768 > ), class = "Date")), .Names = c("Date", "Year", "Station", "Abun", > "Date1"), row.names = c(NA, 10L), class = "data.frame") > > Raw$Date1<-as.Date(Raw$Date,"%d/%m") > xyplot(Abun~Date1|as.factor(Year),Raw,type="p",xlab=list("Month",cex=1.5),ylab=list("Abundance",cex=1.5),cex=2,pch=c(16,16,21),col=c("Black","Grey","Black"),strip=strip.custom(bg='white'),format="%B-%d") > > The date format shown on X-axis was just "10-1", "10-15" > > I should be grateful if any one could help indicating what has gone > wrong? > > 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.____________________________________________________________ FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family! Visit http://www.inbox.com/photosharing to find out more!
Sorry, quick follow-up: is there any chance you used Date rather than Date1 in the original plot? John Kane Kingston ON Canada> -----Original Message----- > From: r-help at r-project.org > Sent: Mon, 17 Aug 2015 21:15:39 -0700 > To: r-help at r-project.org > Subject: [R] date format in xyplot > > To whom it may concern, > > I have tried to plot some numbers against time with the time on the > X-axis shown as "Jan", "Feb", etc. > > I used the following commands: > Raw<-structure(list(Date = structure(c(6L, 7L, 2L, 4L, 12L, 9L, 7L, > 2L, 4L, 12L), .Label = c("1/10", "1/11", "11/11", "12/11", "13/10", > "19/9", "2/10", "2/11", "20/9", "26/11", "29/10", "29/11", "30/11", > "31/10", "4/10", "6/10"), class = "factor"), Year = c(2002L, > 2002L, 2002L, 2002L, 2002L, 2002L, 2002L, 2002L, 2002L, 2002L > ), Station = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, > 2L), .Label = c("E", "F", "H", "I"), class = "factor"), Abun = c(3.42, > 1.33, 3.67, 3.67, 3.92, 2.17, 2.5, 1.67, 6.33, 0.67), Date1 > structure(c(16697, > 16710, 16740, 16751, 16768, 16698, 16710, 16740, 16751, 16768 > ), class = "Date")), .Names = c("Date", "Year", "Station", "Abun", > "Date1"), row.names = c(NA, 10L), class = "data.frame") > > Raw$Date1<-as.Date(Raw$Date,"%d/%m") > xyplot(Abun~Date1|as.factor(Year),Raw,type="p",xlab=list("Month",cex=1.5),ylab=list("Abundance",cex=1.5),cex=2,pch=c(16,16,21),col=c("Black","Grey","Black"),strip=strip.custom(bg='white'),format="%B-%d") > > The date format shown on X-axis was just "10-1", "10-15" > > I should be grateful if any one could help indicating what has gone > wrong? > > 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.____________________________________________________________ FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!
Thank you Duncan,
I have tried the scales function. It ends up with 2015-09-15, which is
acceptable. It is far much better than "09 15" shown on the axis. The
problem is the data were obtained in different years. This makes
"2015" shown in lattice plots of different years. I have tried to put
in the year in the raw data (such as "1/10/2013"), but the plot is
really bizzard, with the 2002 plots have all the points on the left of the plot
whereas 2013 plots have all the data points on the right of the plots because
the x-axis shows data from 2001 to 2013. I feel like hopeless to insist to have
the axis label shown as "Sep 15" because it seems to be the problem of
my computer setting. Is there a way to shows graphs in different years, but
with the same scale beginning from September to December?
Regards,
Christine
--------------------------------------------
2015?8?18? ????Duncan Mackay <dulcalma at bigpond.com> ???
??: RE: [R] date format in xyplot
???: "R" <r-help at r-project.org>
??: 2015?8?18?,???,??4:08
Hi Christine
If somethings go wrong:
1 first check your data
str(Raw)
'data.frame':???10 obs. of?
5 variables:
$ Date???: Factor
w/ 16 levels "1/10","1/11",..: 6 7 2 4
12 9 7 2 4 12
$ Year???: int?
2002 2002 2002 2002 2002 2002 2002 2002 2002 2002
$ Station: Factor w/ 4 levels
"E","F","H","I": 1 1
1 1 1 2 2 2 2 2
$ Abun???: num?
3.42 1.33 3.67 3.67 3.92 2.17 2.5 1.67 6.33 0.67
$ Date1? : Date, format:
"2015-09-19" "2015-10-02"
"2015-11-01"
"2015-11-12" ...
Raw$Date2 <- as.character(Raw$Date1)
Raw$Date2
[1]
"2015-09-19" "2015-10-02"
"2015-11-01" "2015-11-12"
"2015-11-29"
"2015-09-20" "2015-10-02"
"2015-11-01" "2015-11-12"
"2015-11-29"
Raw$Date2 <-
as.Date(Raw$Date2, "%Y-%m-%d")
2 read the help guide again if not done
recently ?lattice::xyplot or ?xyplot
3 start
with a minimum number of arguments
xyplot(Abun~Date2|as.factor(Year), Raw)
or
xyplot(Abun~Date2, Raw)
if you are still having problems
Dates are hard work in any
language as they are not consistent so:
a.?
use? default
b.? use your own
This works
xyplot(Abun~Date2|as.factor(Year), Raw,
? ? ???par.settings list(stripbackground = "transparent"), #
background
colour controlled here
? ? ???type="p",
? ? ???scales = list(x = list(at sort(c(seq(as.Date(Raw$Date2[1]-4), by
"months", length = 4),
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
? ? ? ? ???seq(as.Date(Raw$Date2[1]+12),
by
= "months", length = 3))),
? ? ? ? ? ? ? ? ? ? ? ? ? ?
???labels format(sort(c(seq(as.Date(Raw$Date2[1]-4), by "months",
length = 4),
seq(as.Date(Raw$Date2[1]+12), by "months", length = 3))),
"%m-%d") )
),
? ?
???xlab=list("Month",cex=1.5),
? ?
???ylab=list("Abundance",cex=1.5),
? ? ???cex=2,
?
? ???pch=c(16,16,21),
? ?
???col=c("Black","Grey","Black")
)
par.settings
is confining the parameters set by trellis.par.set()? to
the
function
to get them
names(trellis.par.get() )
and going further
trellis.par.get()$superpose.symbol
will give you the values for
superpose.symbol
Beware: Do
not make the labels etc so big that the axis labels are hard
to
read. Think of final size
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: Tuesday, 18 August 2015 14:16
To: r-help at r-project.org
Subject: [R] date format in xyplot
To whom it may concern,
I have tried to plot some
numbers against time with the time on the X-axis
shown as "Jan", "Feb",
etc.
I used the following
commands:
Raw<-structure(list(Date structure(c(6L, 7L, 2L, 4L, 12L, 9L, 7L,
2L, 4L, 12L), .Label = c("1/10",
"1/11", "11/11", "12/11",
"13/10",
"19/9",
"2/10", "2/11", "20/9",
"26/11", "29/10", "29/11",
"30/11",
"31/10",
"4/10", "6/10"), class "factor"), Year =
c(2002L,
2002L,
2002L, 2002L, 2002L, 2002L, 2002L, 2002L, 2002L, 2002L
), Station = structure(c(1L, 1L, 1L, 1L, 1L,
2L, 2L, 2L, 2L,
2L), .Label c("E", "F", "H",
"I"), class = "factor"), Abun = c(3.42,
1.33, 3.67, 3.67, 3.92, 2.17, 2.5, 1.67,
6.33, 0.67), Date1 structure(c(16697,
16710, 16740, 16751, 16768, 16698, 16710,
16740, 16751, 16768
), class "Date")), .Names = c("Date",
"Year", "Station", "Abun",
"Date1"), row.names = c(NA, 10L),
class = "data.frame")
Raw$Date1<-as.Date(Raw$Date,"%d/%m")
xyplot(Abun~Date1|as.factor(Year),Raw,type="p",xlab=list("Month",cex=1.5),yl
ab=list("Abundance",cex=1.5),cex=2,pch=c(16,16,21),col=c("Black","Grey","Bla
ck"),strip=strip.custom(bg='white'),format="%B-%d")
The date format shown on
X-axis was just "10-1", "10-15"
I should be grateful if any
one could help indicating what has gone wrong?
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.