Re: [R] Order labels in qplot() - ggplot2 {help}

From: baptiste auguie <bapt4510_at_googlemail.com>
Date: Thu, 10 Jun 2010 20:50:13 +0200

Hi,

You could reorder the factor levels before plotting,

x$n = factor(x$n, levels=c("va","vp", letters[1:3]))

last_plot() %+% x

or you could avoid using factors in the first place,

 x <- data.frame(cbind(n,p,pm,pn), stringsAsFactors=FALSE)

last_plot() %+% x

HTH, baptiste

On Thu, Jun 10, 2010 at 8:42 PM, Kim Jung Hwa <kimhwamaillist_at_gmail.com> wrote:
> Hello,
>
> I want to arrage the label according to my preference eg.. (va, vp, a, b,
> c) but don't know how to supress default ordering. Any
> suggestions?
>
> Please try the code below:
>
> n <- c("va", "vp", "a", "b", "c")
> p <- c(2, 2,1, 3,5)
> pm<- c(3,4,2,5,4)
> pn <- c(1,1,1,2,3)
> x<-data.frame(cbind(n,p,pm,pn))
> library(ggplot2)
> qplot(x=n, y=p, data=x, ymin=pn, ymax=pm,
>   xlab='', ylab='', main='Order Label as: va vp a b c') +
>   geom_hline(yintercept = 2) +
>   geom_linerange() +
>   coord_flip()
>
> Thanks!
>
> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggplot2_at_googlegroups.com
> To unsubscribe: email ggplot2+unsubscribe_at_googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>



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. Received on Thu 10 Jun 2010 - 19:32:03 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 10 Jun 2010 - 20:31:39 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive