geom_hline

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

geom_hline

Felipe Carrillo
 Hi all:
I am trying to draw a horizontal line along the zero
"Y axis" value but since zero isn't showing therefore
the line is not drawn. If I set my intercept to 15
then it'll work but I dont want to hardcode it because
the Y axis parameters could be different for another
variable. I would like to alway set my hline along the
zero as default. Thanks

p <- ggplot(mtcars, aes(x = wt, y=mpg)) + geom_point()
p + geom_hline(intercept=0)

Felipe D. Carrillo
  Fishery Biologist
  US Fish & Wildlife Service
  California, USA



      ____________________________________________________________________________________
Looking for last minute shopping deals?

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: geom_hline

Jim Lemon
Felipe Carrillo wrote:

>  Hi all:
> I am trying to draw a horizontal line along the zero
> "Y axis" value but since zero isn't showing therefore
> the line is not drawn. If I set my intercept to 15
> then it'll work but I dont want to hardcode it because
> the Y axis parameters could be different for another
> variable. I would like to alway set my hline along the
> zero as default. Thanks
>
> p <- ggplot(mtcars, aes(x = wt, y=mpg)) + geom_point()
> p + geom_hline(intercept=0)
>
Hi Felipe,
It sounds like you want to include zero in the axis. In base graphics,
you would use:

ylim=c(0,maxy)

where maxy specifies the upper end of the ordinate. I had a quick look
at the ggplot2 docs, but I haven't yet found whether this works in that
system.

Jim

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: geom_hline

Thierry Onkelinx
Felipe,
 
You'll need to define the limits yourself with scale_y_continuous.
 
library(ggplot2)
p <- ggplot(mtcars, aes(x = wt, y=mpg)) + geom_point()
p + geom_hline(intercept=0) + scale_y_continuous(limits = c(0, max(mtcars$mpg)))

Cheers,
 
Thierry

________________________________

Van: [hidden email] namens Jim Lemon
Verzonden: di 25-12-2007 10:16
Aan: Felipe Carrillo
CC: [hidden email]
Onderwerp: Re: [R] geom_hline



Felipe Carrillo wrote:

>  Hi all:
> I am trying to draw a horizontal line along the zero
> "Y axis" value but since zero isn't showing therefore
> the line is not drawn. If I set my intercept to 15
> then it'll work but I dont want to hardcode it because
> the Y axis parameters could be different for another
> variable. I would like to alway set my hline along the
> zero as default. Thanks
>
> p <- ggplot(mtcars, aes(x = wt, y=mpg)) + geom_point()
> p + geom_hline(intercept=0)
>
Hi Felipe,
It sounds like you want to include zero in the axis. In base graphics,
you would use:

ylim=c(0,maxy)

where maxy specifies the upper end of the ordinate. I had a quick look
at the ggplot2 docs, but I haven't yet found whether this works in that
system.

Jim

______________________________________________
[hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: geom_hline

hadley wickham
On Dec 25, 2007 9:32 PM, ONKELINX, Thierry <[hidden email]> wrote:
> Felipe,
>
> You'll need to define the limits yourself with scale_y_continuous.
>
> library(ggplot2)
> p <- ggplot(mtcars, aes(x = wt, y=mpg)) + geom_point()
> p + geom_hline(intercept=0) + scale_y_continuous(limits = c(0, max(mtcars$mpg)))

Or

p + geom_hline(intercept=0) + scale_y_continuous(limits = c(0, NA))

-  the NA means that it will calculate the maximum from the data.

Hadley

--
http://had.co.nz/

______________________________________________
[hidden email] 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.