customise tick marks

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

customise tick marks

roslinazairimah zakaria
Dear r-users,

I want to draw dotplot for mtcars data according to cyl. There are three
types of cylinder 4,6,8. However when we draw it does not use 4,6,8 instead
label it as 1,2,3.

I have this code and would like to customise the tick mark according to cyl
groups:


dotplot(cyl ~ mpg, data = mtcars, groups = cyl, cex=1.2,axes=FALSE,
  main="Gas Milage for Car Models",  xlab="Miles Per Gallon")
ticks = c(1,2,3)
axis(2, at = ticks, labels=c(4,6,8))

I got this message:

axis(2, at = ticks, labels=c(4,6,8))
Error in axis(2, at = ticks, labels = c(4, 6, 8)) :
  plot.new has not been called yet

Thank you so much for any help given.
--
*Roslinazairimah Zakaria*
*Tel: +609-5492370; Fax. No.+609-5492766*

*Email: [hidden email] <[hidden email]>;
[hidden email] <[hidden email]>*
Faculty of Industrial Sciences & Technology
University Malaysia Pahang
Lebuhraya Tun Razak, 26300 Gambang, Pahang, Malaysia

        [[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: customise tick marks

Jim Lemon-4
Hi Roslinazairimah,
You seem to be using the dotplot function from the lattice package. If so:

dotplot(cyl ~ mpg, data = mtcars, groups = cyl, cex=1.2,
 scales=list(y=list(labels=sort(unique(mtcars$cyl)))),
 main="Gas Milage for Car Models",  xlab="Miles Per Gallon")

Jim
On Wed, Sep 12, 2018 at 4:21 PM roslinazairimah zakaria
<[hidden email]> wrote:

>
> Dear r-users,
>
> I want to draw dotplot for mtcars data according to cyl. There are three
> types of cylinder 4,6,8. However when we draw it does not use 4,6,8 instead
> label it as 1,2,3.
>
> I have this code and would like to customise the tick mark according to cyl
> groups:
>
>
> dotplot(cyl ~ mpg, data = mtcars, groups = cyl, cex=1.2,axes=FALSE,
>   main="Gas Milage for Car Models",  xlab="Miles Per Gallon")
> ticks = c(1,2,3)
> axis(2, at = ticks, labels=c(4,6,8))
>
> I got this message:
>
> axis(2, at = ticks, labels=c(4,6,8))
> Error in axis(2, at = ticks, labels = c(4, 6, 8)) :
>   plot.new has not been called yet
>
> Thank you so much for any help given.
> --
> *Roslinazairimah Zakaria*
> *Tel: +609-5492370; Fax. No.+609-5492766*
>
> *Email: [hidden email] <[hidden email]>;
> [hidden email] <[hidden email]>*
> Faculty of Industrial Sciences & Technology
> University Malaysia Pahang
> Lebuhraya Tun Razak, 26300 Gambang, Pahang, Malaysia
>
>         [[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: customise tick marks

roslinazairimah zakaria
Hi Jim,
It works beautifully.

Thank you very much for your help.


On Wed, Sep 12, 2018 at 5:58 PM Jim Lemon <[hidden email]> wrote:

> Hi Roslinazairimah,
> You seem to be using the dotplot function from the lattice package. If so:
>
> dotplot(cyl ~ mpg, data = mtcars, groups = cyl, cex=1.2,
>  scales=list(y=list(labels=sort(unique(mtcars$cyl)))),
>  main="Gas Milage for Car Models",  xlab="Miles Per Gallon")
>
> Jim
> On Wed, Sep 12, 2018 at 4:21 PM roslinazairimah zakaria
> <[hidden email]> wrote:
> >
> > Dear r-users,
> >
> > I want to draw dotplot for mtcars data according to cyl. There are three
> > types of cylinder 4,6,8. However when we draw it does not use 4,6,8
> instead
> > label it as 1,2,3.
> >
> > I have this code and would like to customise the tick mark according to
> cyl
> > groups:
> >
> >
> > dotplot(cyl ~ mpg, data = mtcars, groups = cyl, cex=1.2,axes=FALSE,
> >   main="Gas Milage for Car Models",  xlab="Miles Per Gallon")
> > ticks = c(1,2,3)
> > axis(2, at = ticks, labels=c(4,6,8))
> >
> > I got this message:
> >
> > axis(2, at = ticks, labels=c(4,6,8))
> > Error in axis(2, at = ticks, labels = c(4, 6, 8)) :
> >   plot.new has not been called yet
> >
> > Thank you so much for any help given.
> > --
> > *Roslinazairimah Zakaria*
> > *Tel: +609-5492370; Fax. No.+609-5492766*
> >
> > *Email: [hidden email] <[hidden email]>;
> > [hidden email] <[hidden email]>*
> > Faculty of Industrial Sciences & Technology
> > University Malaysia Pahang
> > Lebuhraya Tun Razak, 26300 Gambang, Pahang, Malaysia
> >
> >         [[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.
>


--
*Roslinazairimah Zakaria*
*Tel: +609-5492370; Fax. No.+609-5492766*

*Email: [hidden email] <[hidden email]>;
[hidden email] <[hidden email]>*
Faculty of Industrial Sciences & Technology
University Malaysia Pahang
Lebuhraya Tun Razak, 26300 Gambang, Pahang, Malaysia

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