[R] help with adding lines to current plot

Joshua Wiley jwiley.psych at gmail.com
Mon Oct 25 23:47:36 CEST 2010


Dear Changbin,

The lines do not show up because they are outside the region of your
graph.  If you add the yaxis labels back in you will see this.  You
can avoid it by specifying ylim argument in plot() rather than letting
R decide by itself.

Here is revised code:

x <- seq(0,10, by=1)
y <- c(0.952, 0.947, 0.943, 0.941, 0.933, 0.932, 0.939, 0.932, 0.924,
0.918, 0.920) # missense
z <- c(0.068, 0.082, 0.080, 0.099, 0.108, 0.107, 0.101, 0.105, 0.118,
0.130, 0.132) # missense False Negative

par()$mar  #view the value of margin  [1] 5.1 4.1 4.1 2.1

# create extra margin room on the right for an axis
par(mar=c(5, 4, 4, 8) + 0.1)

# plot x vs. y
plot(x, y,type="b", pch=21, col="red", yaxt="n", lty=3, xlab="",
ylab="", ylim = c(min(c(y, z)), max(c(y, z))))

# add x vs. fp
lines(x, z, type="b", pch=22, col="blue", lty=2)


Cheers,

Josh

On Mon, Oct 25, 2010 at 2:38 PM, Changbin Du <changbind at gmail.com> wrote:
> HI, Dear R community,
>
> I am using the following codes to plot, however, the lines code works. But
> the line was not drawn on the previous plot and did not shown up.
>
> How comes?
>
>
> # specify the data for missense simulation
> x <- seq(0,10, by=1)
> y <- c(0.952, 0.947, 0.943, 0.941, 0.933, 0.932, 0.939, 0.932, 0.924, 0.918,
> 0.920) # missense
> z <- c(0.068, 0.082, 0.080, 0.099, 0.108, 0.107, 0.101, 0.105, 0.118, 0.130,
> 0.132) # missense False Negative
>
> par()$mar  #view the value of margin  [1] 5.1 4.1 4.1 2.1
>
> # create extra margin room on the right for an axis
> par(mar=c(5, 4, 4, 8) + 0.1)
>
>
> # plot x vs. y
> plot(x, y,type="b", pch=21, col="red", yaxt="n", lty=3, xlab="", ylab="")
>
> # add x vs. fp
> lines(x, z, type="b", pch=22, col="blue", lty=2)
>
> --
> Sincerely,
> Changbin
>
> --
> Sincerely,
> Changbin
> --
>
>        [[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