[R] how to control ticks

jim holtman jholtman at gmail.com
Wed Dec 22 22:51:16 CET 2010


Try this.  Made up some data with year values:

myDates <- seq(2009, 2011, .01)  # create some dates
myData <- runif(length(myDates))
plot(myDates, myData)
# now convert to a Date by determining what the date of the first value is
first <- as.Date(paste(floor(min(myDates)), '-1-1', sep = ''))
# add the 'days' to the date
myNewDates <- first + (myDates - floor(min(myDates))) * 365.25  # rough estimate
# replot
plot(myNewDates, myData)
# quarters
ticks <- seq(first, max(myNewDates), by = '3 months')
axis(1, at = ticks, labels = rep('', length(ticks)))



On Wed, Dec 22, 2010 at 12:24 AM, Yogesh Tiwari
<yogesh.mpi at googlemail.com> wrote:
> Hi Jim,
> Yes you are right, file$time is decimal date. In the attached plot I want to
> replace decimal
> date with proper time axis so I can show month ticks. Decimal date misleads
> sometime
> while interpretation. Data varies from Jan-Dec 2009.
> Thanks,
> Yogesh
> On Tue, Dec 21, 2010 at 9:57 PM, jim holtman <jholtman at gmail.com> wrote:
>>
>> What is the structure of file$time? Is it Date/POSIXct?  'at=1:12'
>> only works if those are the dimensions of file$time.  So give us an
>> idea of what the data is (PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html and provide commented,
>> minimal, self-contained, reproducible code).
>>
>>
>>
>> On Tue, Dec 21, 2010 at 7:36 AM, Yogesh Tiwari
>> <yogesh.mpi at googlemail.com> wrote:
>> > Hi,
>> > I want 12 ticks at axis 1 and want to write Jan-Dec on each.
>> >
>> > something like:
>> >
>> > axis(1, at=1:12,
>> > labels=c('J','F','M','A','M','J','J','A','S','O','N','D'))
>> >
>> > I could omit default ticks but now how to control ticks.
>> >
>> > plot(file$time, file$ch4*1000, ylim=c(1500,1700), xaxt='n', xlab= NA,
>> > ylab=NA,col="blue",yaxs="i",lwd=2, pch=10, type="b")#
>> >
>> > axis(1, at=1:12,
>> > labels=c('J','F','M','A','M','J','J','A','S','O','N','D'))
>> >
>> > BUT above is not working, and there is no error as well.
>> >
>> > Pls help,
>> >
>> > Regards,
>> > Yogesh
>> >
>> >        [[alternative HTML version deleted]]
>> >
>> > ______________________________________________
>> > R-help at r-project.org mailing list
>> > 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.
>> >
>>
>>
>>
>> --
>> Jim Holtman
>> Data Munger Guru
>>
>> What is the problem that you are trying to solve?
>
>
>
> --
> Yogesh K. Tiwari (Dr.rer.nat),
> Scientist,
> Centre for Climate Change Research,
> Indian Institute of Tropical Meteorology,
> Homi Bhabha Road,
> Pashan,
> Pune-411008
> INDIA
>
> Phone: 0091-99 2273 9513 (Cell)
>          : 0091-20-25904452 (O)
> Fax    : 0091-20-258 93 825
>



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?



More information about the R-help mailing list