ordering labels

6 views
Skip to first unread message

Manuel Spínola

unread,
Jul 8, 2010, 9:48:36 PM7/8/10
to ggp...@googlegroups.com
Dear ggplot2 users,

I am trying to do a plot with 95% CI, but the label of the x are ordered
alphabetically.
How can I give the order that I set up in the factor?
Also, how can I make the lines horizontal instead of vertical (I want
the coe in the y axis?

df = data.frame(
coe = factor(c("Intercepto", "Iluminaci�n", "Animales", "Cielo
raso", "Piso", "Paredes")),
resp = c(0.40, 0.11, -0.11, 0.03, -0.03, 0.03),
li = c(0.27, 0.19, 0.007, 0.15, 0.10, 0.15),
ls = c(0.57, 0.002, -0.23, -0.10, -0.18, -0.11))

limits = aes(ymax = ls, ymin= li)

p = ggplot(df, aes(y=resp, x=coe))

p + geom_pointrange(limits)


Best,

Manuel

--
Manuel Sp�nola, Ph.D.
Instituto Internacional en Conservaci�n y Manejo de Vida Silvestre
Universidad Nacional
Apartado 1350-3000
Heredia
COSTA RICA
mspi...@una.ac.cr
mspin...@gmail.com
Tel�fono: (506) 2277-3598
Fax: (506) 2237-7036

Hadley Wickham

unread,
Jul 9, 2010, 1:42:13 AM7/9/10
to Manuel Spínola, ggp...@googlegroups.com
Hi Manuel,

You need to set the order in the factor - look at levels df$coe and
you'll see it's ordered alphabetically.

Hadley

On Fri, Jul 9, 2010 at 3:48 AM, Manuel Spínola <mspin...@gmail.com> wrote:
> Dear ggplot2 users,
>
> I am trying to do a plot with 95% CI, but the label of the x are ordered
> alphabetically.
> How can I give the order that I set up in the factor?
> Also, how can I make the lines horizontal instead of vertical (I want the
> coe in the y axis?
>
> df = data.frame(

>   coe = factor(c("Intercepto", "Iluminación", "Animales", "Cielo raso",


> "Piso", "Paredes")),
>   resp = c(0.40, 0.11, -0.11, 0.03, -0.03, 0.03),
>   li = c(0.27, 0.19, 0.007, 0.15, 0.10, 0.15),
>   ls = c(0.57, 0.002, -0.23, -0.10, -0.18, -0.11))
>
> limits = aes(ymax = ls, ymin= li)
>
> p = ggplot(df, aes(y=resp, x=coe))
>
> p +  geom_pointrange(limits)
>
>
> Best,
>
> Manuel
>
> --

> Manuel Spínola, Ph.D.
> Instituto Internacional en Conservación y Manejo de Vida Silvestre


> Universidad Nacional
> Apartado 1350-3000
> Heredia
> COSTA RICA
> mspi...@una.ac.cr
> mspin...@gmail.com

> Teléfono: (506) 2277-3598
> Fax: (506) 2237-7036
>
> --
> 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 ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>

--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

Felipe Carrillo

unread,
Jul 9, 2010, 10:35:08 AM7/9/10
to Hadley Wickham, Manuel Spínola, ggp...@googlegroups.com
Hi Manuel:
Is this what you want?

df = data.frame(
   coe = factor(c("Intercepto", "Iluminación", "Animales", "Cielo raso","Piso",

"Paredes"),levels=c("Intercepto", "Iluminación", "Animales", "Cielo

raso","Piso", "Paredes")),
   resp = c(0.40, 0.11, -0.11, 0.03, -0.03, 0.03),
   li = c(0.27, 0.19, 0.007, 0.15, 0.10, 0.15),
   ls = c(0.57, 0.002, -0.23, -0.10, -0.18, -0.11))
 limits = aes(ymax = ls, ymin= li)
 p = ggplot(df, aes(y=resp, x=coe))

 p +  geom_pointrange(limits) + coord_flip()
 
Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish & Wildlife Service
California, USA

Reply all
Reply to author
Forward
0 new messages