Problems with geom_vline and geom_hline

57 views
Skip to first unread message

Manuel Spínola

unread,
Jul 9, 2010, 7:38:55 AM7/9/10
to ggplot2
Dear ggplot2 users,

I cannot draw a line in my plot. I tried geom_vline and geom_hline but
it does't work.

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


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

p = ggplot(df, aes(y=Respuesta, x=Coeficiente)) + ylab("Tama�o del Efecto")

p + geom_pointrange(limits, colour = "navyblue", size = 0.8, xlab =
"Tama�o del Efecto") + coord_flip()

p + geom_hline(yintercept=0.0)
Error: tentativa de aplicar una no-funci�n

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

romunov

unread,
Jul 9, 2010, 7:49:14 AM7/9/10
to Manuel Spínola, ggplot2
Is this what you're looking for?

library(ggplot2)
df = data.frame(
        Coeficiente = factor(c("Paredes", "Piso", "Cielo raso", "Animales", "Iluminación", "Intercepto"), levels = c("Paredes", "Piso", "Cielo raso", "Animales", "Iluminación", "Intercepto")),

        Respuesta = c(0.03, -0.03, 0.03, -0.11, 0.11, 0.40),
        li = c(0.15, 0.10, 0.15, 0.007, 0.19, 0.27),
        ls = c(-0.11, -0.18, -0.10, -0.23, 0.002, 0.57))


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

p = ggplot(df, aes(y=Respuesta, x=Coeficiente)) + ylab("Tamaño del Efecto")

p2 <- p +  geom_pointrange(limits, colour = "navyblue", size = 0.8, xlab = "Tamaño del Efecto") + coord_flip()

p2 + geom_hline(yintercept=0)


Cheers,
Roman

On Fri, Jul 9, 2010 at 1:38 PM, Manuel Spínola <mspin...@gmail.com> wrote:
Dear ggplot2 users,

I cannot draw a line in my plot.  I tried geom_vline and geom_hline but it does't work.

df = data.frame(
  Coeficiente = factor(c("Paredes", "Piso", "Cielo raso", "Animales", "Iluminación", "Intercepto"), levels = c("Paredes", "Piso", "Cielo raso", "Animales", "Iluminación", "Intercepto")),

  Respuesta = c(0.03, -0.03, 0.03, -0.11, 0.11, 0.40),
  li = c(0.15, 0.10, 0.15, 0.007, 0.19, 0.27),
  ls = c(-0.11, -0.18, -0.10, -0.23, 0.002, 0.57))


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

p = ggplot(df, aes(y=Respuesta, x=Coeficiente)) + ylab("Tamaño del Efecto")

p +  geom_pointrange(limits, colour = "navyblue", size = 0.8, xlab = "Tamaño del Efecto") + coord_flip()

p + geom_hline(yintercept=0.0)
Error: tentativa de aplicar una no-función

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



--
In God we trust, all others bring data.

Phil Taylor

unread,
Jul 9, 2010, 7:52:28 AM7/9/10
to ggp...@googlegroups.com
You need to do

p + geom_pointrange(...) + geom_hline(xintercept = 0.0)

Phil Taylor

On 7/9/2010 8:38 AM, Manuel Sp�nola wrote:
> Dear ggplot2 users,
>
> I cannot draw a line in my plot. I tried geom_vline and geom_hline but
> it does't work.
>
> df = data.frame(
> Coeficiente = factor(c("Paredes", "Piso", "Cielo raso", "Animales",
> "Iluminaci�n", "Intercepto"), levels = c("Paredes", "Piso", "Cielo
> raso", "Animales", "Iluminaci�n", "Intercepto")),
> Respuesta = c(0.03, -0.03, 0.03, -0.11, 0.11, 0.40),
> li = c(0.15, 0.10, 0.15, 0.007, 0.19, 0.27),
> ls = c(-0.11, -0.18, -0.10, -0.23, 0.002, 0.57))
>
>
> limits = aes(ymax = ls, ymin= li)
>
> p = ggplot(df, aes(y=Respuesta, x=Coeficiente)) + ylab("Tama�o del Efecto")
>
> p + geom_pointrange(limits, colour = "navyblue", size = 0.8, xlab =
> "Tama�o del Efecto") + coord_flip()
>
> p + geom_hline(yintercept=0.0)
> Error: tentativa de aplicar una no-funci�n
>
> Best,
>
> Manuel
>
>

--
Phil Taylor
Bird Studies Canada Chair in Ornithology
Department of Biology, Acadia University
Wolfville, NS, Canada
902-585-1287

Reply all
Reply to author
Forward
0 new messages