x-axis tick marks on log scale plot

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

x-axis tick marks on log scale plot

Brian Smith
Hi,

I have a plot with log scale on the axes. How do I add ticks and labels in
addition to the ones provided by default? Can I specify where I want the
ticks and labels?

For example:

set.seed(12345)
x <- sample(1:10000,10)
y <- sample(1:10000,10)

plot(x,y,log="xy")


For me, this plot has tick marks (and labels) at 2000, 4000, 6000, 8000.
How can I make the axes so that it has marks and labels at 1000 intervals
(i.e. 2000, 3000, 4000, etc.)

thanks!

        [[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: x-axis tick marks on log scale plot

Duncan Murdoch-2
On 19/05/2016 9:40 AM, Brian Smith wrote:

> Hi,
>
> I have a plot with log scale on the axes. How do I add ticks and labels in
> addition to the ones provided by default? Can I specify where I want the
> ticks and labels?
>
> For example:
>
> set.seed(12345)
> x <- sample(1:10000,10)
> y <- sample(1:10000,10)
>
> plot(x,y,log="xy")
>
>
> For me, this plot has tick marks (and labels) at 2000, 4000, 6000, 8000.
> How can I make the axes so that it has marks and labels at 1000 intervals
> (i.e. 2000, 3000, 4000, etc.)

You'll get ticks on side 1 (the x axis) by using

axis(1, at=1000*(2:10))

You'll get labels at some of those locations; R will leave some out, if
it looks as though the labels will overlap.  Using las=2 will make them
perpendicular to the axis, and all should be drawn.

Duncan Murdoch

______________________________________________
[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: x-axis tick marks on log scale plot

Ivan Calandra-4
In reply to this post by Brian Smith
Hi,

You can do it by first plotting your values without the x-axis:
plot(x,y,log="xy", xaxt="n")

and then plotting the x-axis with ticks where you need to:
axis(side=1, at=seq(2000,8000,1000))

HTH,
Ivan

--
Ivan Calandra, PhD
Scientific Mediator
University of Reims Champagne-Ardenne
GEGENAA - EA 3795
CREA - 2 esplanade Roland Garros
51100 Reims, France
+33(0)3 26 77 36 89
[hidden email]
--
https://www.researchgate.net/profile/Ivan_Calandra
https://publons.com/author/705639/

Le 19/05/2016 à 15:40, Brian Smith a écrit :

> Hi,
>
> I have a plot with log scale on the axes. How do I add ticks and labels in
> addition to the ones provided by default? Can I specify where I want the
> ticks and labels?
>
> For example:
>
> set.seed(12345)
> x <- sample(1:10000,10)
> y <- sample(1:10000,10)
>
> plot(x,y,log="xy")
>
>
> For me, this plot has tick marks (and labels) at 2000, 4000, 6000, 8000.
> How can I make the axes so that it has marks and labels at 1000 intervals
> (i.e. 2000, 3000, 4000, etc.)
>
> thanks!
>
> [[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.
>

______________________________________________
[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: x-axis tick marks on log scale plot

Brian Smith
Thanks all !!

On Thu, May 19, 2016 at 9:55 AM, Ivan Calandra <[hidden email]>
wrote:

> Hi,
>
> You can do it by first plotting your values without the x-axis:
> plot(x,y,log="xy", xaxt="n")
>
> and then plotting the x-axis with ticks where you need to:
> axis(side=1, at=seq(2000,8000,1000))
>
> HTH,
> Ivan
>
> --
> Ivan Calandra, PhD
> Scientific Mediator
> University of Reims Champagne-Ardenne
> GEGENAA - EA 3795
> CREA - 2 esplanade Roland Garros
> 51100 Reims, France
> +33(0)3 26 77 36 89
> [hidden email]
> --
> https://www.researchgate.net/profile/Ivan_Calandra
> https://publons.com/author/705639/
>
>
> Le 19/05/2016 à 15:40, Brian Smith a écrit :
>
>> Hi,
>>
>> I have a plot with log scale on the axes. How do I add ticks and labels in
>> addition to the ones provided by default? Can I specify where I want the
>> ticks and labels?
>>
>> For example:
>>
>> set.seed(12345)
>> x <- sample(1:10000,10)
>> y <- sample(1:10000,10)
>>
>> plot(x,y,log="xy")
>>
>>
>> For me, this plot has tick marks (and labels) at 2000, 4000, 6000, 8000.
>> How can I make the axes so that it has marks and labels at 1000 intervals
>> (i.e. 2000, 3000, 4000, etc.)
>>
>> thanks!
>>
>>         [[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.
>>
>>
> ______________________________________________
> [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: x-axis tick marks on log scale plot

Martin Maechler
>>>>> Brian Smith <[hidden email]>
>>>>>     on Thu, 19 May 2016 11:04:55 -0400 writes:

    > Thanks all !!  On Thu, May 19, 2016 at 9:55 AM, Ivan
    > Calandra <[hidden email]> wrote:

    >> Hi,
    >>
    >> You can do it by first plotting your values without the
    >> x-axis: plot(x,y,log="xy", xaxt="n")
    >>
    >> and then plotting the x-axis with ticks where you need to:
    >> axis(side=1, at=seq(2000,8000,1000))

Getting nicer looking axis ticks  for log-scale axes (and
traditional graphics) I have created the function
   eaxis()
and utility function    pretty10exp(.)

and I also created standard R's  axTicks(.)  to help with these.

    if(!require("sfsmisc")) install.packages("sfsmisc")
    require("sfsmisc")

    x <- lseq(1e-10, 0.1, length = 201)
    plot(x, pt(x, df=3), type = "l", xaxt = "n", log = "x")
    eaxis(1)

gives the attached plot


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

eaxis-log-example.pdf (7K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: x-axis tick marks on log scale plot

Robert Baer
Very, very nice.  Thanks for sharing.


On 5/20/2016 4:21 AM, Martin Maechler wrote:

>>>>>> Brian Smith <[hidden email]>
>>>>>>      on Thu, 19 May 2016 11:04:55 -0400 writes:
>      > Thanks all !!  On Thu, May 19, 2016 at 9:55 AM, Ivan
>      > Calandra <[hidden email]> wrote:
>
>      >> Hi,
>      >>
>      >> You can do it by first plotting your values without the
>      >> x-axis: plot(x,y,log="xy", xaxt="n")
>      >>
>      >> and then plotting the x-axis with ticks where you need to:
>      >> axis(side=1, at=seq(2000,8000,1000))
>
> Getting nicer looking axis ticks  for log-scale axes (and
> traditional graphics) I have created the function
>     eaxis()
> and utility function    pretty10exp(.)
>
> and I also created standard R's  axTicks(.)  to help with these.
>
>      if(!require("sfsmisc")) install.packages("sfsmisc")
>      require("sfsmisc")
>
>      x <- lseq(1e-10, 0.1, length = 201)
>      plot(x, pt(x, df=3), type = "l", xaxt = "n", log = "x")
>      eaxis(1)
>
> gives the attached plot
>
>
>
> ______________________________________________
> [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.