[R] plot month and year

linda.s samrobertsmith at gmail.com
Sat Jul 17 20:41:21 CEST 2010


i am a beginner and tried to provide a reproducible example. is the
following style a correct one?
Thanks.

> dput(unem)
> structure(list(a = c(10.2, 9.8, 9.5, 8.3, 7.9, 8.8, 8.9, 9.3,
+ 9.2, 9, 9.5, 12, 15.7, 16.1, 15.4, 14.7, 13.9, 15.3, 15.4, 15,
+ 13.8, 13.9, 14.1, 15.8), b = c(7, 6.7, 6.8, 6.1, 6.5, 7.4, 8.4,
+ 7.6, 7.5, 7.5, 7.8, 9.1, 11.2, 12.1, 12.2, 11.5, 11.5, 11.7,
+ 11.7, 11.2, 10.3, 10.7, 10.8, 11.6), c = c(6.5, 5.9, 5.9, 5.4,
+ 6.1, 6.6, 7.6, 7.2, 6.9, 7.1, 7.7, 8.4, 11.6, 11.3, 11, 10.9,
+ 12, 12.7, 12.8, 11, 10, 10.1, 10.3, 11.1), d = c(8.3, 7.6, 7.3,
+ 6.2, 6.2, 7.1, 8.5, 8.3, 7.7, 7.3, 8, 10.2, 13.9, 14.9, 14.8,
+ 13.1, 13.1, 13.3, 13.3, 12.1, 11.1, 11.3, 11.6, 12.7)), .Names = c("a",
+ "b", "c", "d"), class = "data.frame", row.names = c("JAN_08",
+ "FEB_08", "MAR_08", "APR_08", "MAY_08", "JUN_08", "JULY_08",
+ "AUG_08", "SEP_08", "OCT_08", "NOV_08", "DEC_08", "JAN_09", "FEB_09",
+ "MAR_09", "APR_09", "MAY_09", "JUN_09", "JUL_09", "AUG_09", "SEP_09",
+ "OCT_09", "NOV_09", "DEC_09"))
           a    b    c    d
JAN_08  10.2  7.0  6.5  8.3
FEB_08   9.8  6.7  5.9  7.6
MAR_08   9.5  6.8  5.9  7.3
APR_08   8.3  6.1  5.4  6.2
MAY_08   7.9  6.5  6.1  6.2
JUN_08   8.8  7.4  6.6  7.1
JULY_08  8.9  8.4  7.6  8.5
AUG_08   9.3  7.6  7.2  8.3
SEP_08   9.2  7.5  6.9  7.7
OCT_08   9.0  7.5  7.1  7.3
NOV_08   9.5  7.8  7.7  8.0
DEC_08  12.0  9.1  8.4 10.2
JAN_09  15.7 11.2 11.6 13.9
FEB_09  16.1 12.1 11.3 14.9
MAR_09  15.4 12.2 11.0 14.8
APR_09  14.7 11.5 10.9 13.1
MAY_09  13.9 11.5 12.0 13.1
JUN_09  15.3 11.7 12.7 13.3
JUL_09  15.4 11.7 12.8 13.3
AUG_09  15.0 11.2 11.0 12.1
SEP_09  13.8 10.3 10.0 11.1
OCT_09  13.9 10.7 10.1 11.3
NOV_09  14.1 10.8 10.3 11.6
DEC_09  15.8 11.6 11.1 12.7
> attach(unem)
The following object(s) are masked from 'unem (position 3)':

    a, b, c, d
The following object(s) are masked from 'unem (position 4)':

    a, b, c, d
> unem1 <- ts(unem$a, start = c(2008, 1), freq = 12)
> plot(unem1, type = "o")

Question:
The X axis on the plot now starts from 2008.0; Since the data starts
from January 2008, can I make it 2008.1, and also show 2009.12 on the
axis?
Thanks.

On Wed, Jul 14, 2010 at 9:49 AM, Achim Zeileis <Achim.Zeileis at uibk.ac.at> wrote:
> You do not provide a reproducible example, as the posting guide asks you to.
> But I guess that your time series setup using ts() is insufficient, see ?ts.
> If the data starts in January 2008, why do you tell R that it starts in 1?
> Presumably you have monthly data and
>
>  unem1 <- ts(unem$a, start = c(2008, 1), freq = 12)
>  plot(unem1, type = "o")
>
> is what you want.
>
> hth,
> Z
>
> On Wed, 14 Jul 2010, linda.s wrote:
>
>> R Code begins
>> unem=read.csv("book5.csv",header=T,row.names=1)
>> attach(unem)
>> unem1=ts(unem$a, start=1)
>> ts.plot(unem1,main="a")
>> points(unem1,type="o")
>> R Code ends
>>
>> because the time starts at JAN_08 and ends on DEC_09, how to make the
>> y axis in the plot show month starting from JAN_08 instead of having
>> the current
>> ugly appearance (5, 10, 15, 20,?)?
>>
>> On Wed, Jul 14, 2010 at 9:20 AM, linda.s <samrobertsmith at gmail.com> wrote:
>>>
>>> R Code begins
>>> unem=read.csv("book5.csv",header=T,row.names=1)
>>> attach(unem)
>>> unem1=ts(unem$Allen, start=1)
>>> ts.plot(unem1,main="Allen")
>>> points(unem1,type="o")
>>> R Code ends
>>>
>>> because the time starts at JAN_08 and ends on DEC_09, how to make the
>>> y axis in the plot show month starting from JAN_08 instead of having
>>> the current
>>> ugly appearance (5, 10, 15, 20,?)?
>>>
>>
>



More information about the R-help mailing list