[R] Plotting just a portion of a smoother graph in ggplot2

Timothy Bates timothy.c.bates at gmail.com
Thu Aug 4 16:51:37 CEST 2011


It's not immediately obvious

You need to look at coord_cartesian() and its ylim argument. 

Best, t

Sent from my iPhone

On 4 Aug 2011, at 02:38 PM, Christopher Desjardins <cddesjardins at gmail.com> wrote:

> Hi,
> I am using ggplot2 to with the following code:
> 
> gmathk2 <-
> qplot(time,math,colour=Kids,data=kids.ach.lm.k5,geom="smooth",method="lm",formula=y~ns(x,1))
> + opts(title="Smoother Plot: Math K-5") + xlab("Time") + ylab("Math") +
> scale_colour_brewer(pal="Set1"); gmathk2
> 
> This plots all the smoother for all the x values. What I'd like to do is
> plot the smoother for the x values that are only greater than or equal to 0.
> I don't want this:
> 
> gmathk2 <-
> qplot(time,math,colour=Kids,data=kids.ach.lm.k5,geom="smooth",method="lm",formula=y~ns(x,1))
> + opts(title="Smoother Plot: Math K-5") + xlab("Time") + ylab("Math")  +
> scale_colour_brewer(pal="Set1") + xlim(0,50); gmathk2
> 
> Because adding xlim seems to throw away the data below 0 when calculating
> the smoother. What I want it to do is have ggplot2 give me the same graph as
> the first command but just not plot the part of the smoother that is below
> 0.
> 
> Thanks,
> Chris
> 
>    [[alternative HTML version deleted]]
> 
> ______________________________________________
> 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.



More information about the R-help mailing list