[R] Help with setting the y-axis in a plot.

Joshua Wiley jwiley.psych at gmail.com
Fri Mar 18 07:19:11 CET 2011


Hi Caitlin,

You just need to set the ylim argument to plot (you already did but
g_range is 0, 13 not 0, 15.  So...

On Thu, Mar 17, 2011 at 10:49 PM, Caitlin <bioprogrammer at gmail.com> wrote:
> Hi all.
>
> I'm working on an assignment for a psychology class and I am not sure how to
> adjust the y-axis so it displays the range: 0, 5, 10, 15
>
> The code below is almost ideal:
>
> lsd = c(3, 5, 13)
> mar = c(1, 2, 3)
> g_range <- range(0, lsd, mar)
> plot(lsd, type="o", col="blue", ylim=c(0, 15),
> axes=FALSE, ann=FALSE)

This change to ylim should get you what you want.

Cheers,

Josh

> axis(1, at=1:3, lab=c("Low","Med","High"))
> axis(2, las=1, at=5*0:max(mar))
> box()
> lines(mar, type="o", pch=22, lty=2, col="red")
> title(main="The Effect of Drug Dosage and Type on the Number of
> Hallucinations", col.main="red", font.main=4)
> title(xlab="Dose", col.lab=rgb(0,0.5,0))
> title(ylab="Number of Hallucinations", col.lab=rgb(0,0.5,0))
>
> Thanks,
>
> ~Caitlin
>
>        [[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.
>



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/



More information about the R-help mailing list