[R] Overlapping a Plot with Dataframe

John Kane jrkrideau at inbox.com
Wed Aug 8 16:40:33 CEST 2012



John Kane
Kingston ON Canada


> -----Original Message-----
> From: bioinfo.himanshu at gmail.com
> Sent: Wed, 8 Aug 2012 02:12:00 -0700 (PDT)
> To: r-help at r-project.org
> Subject: Re: [R] Overlapping a Plot with Dataframe
> 
> Hello John,
> 
> in simple term, I have a Plot as an Output.
> Now I want to overlap the plot with a Dataframe having error bar.

That's not what the data suggests. 

> data<- data.frame(
>    x = c(3.00,2.00,3.80,2.40,2.00),
>    error = c(0.0,0.4,1.1,0.7,0.5) )
> --
seems to imply that you are plotting a vector of a data frame and if Jim is correct you then want to plot error bars on the plot, using the error vector in 'data'.  It is just a wording problem but I don't think that you really mean to overlap the plot with another dataframe because you are only showing one data.frame.

In any case, assuming Jim's correct his solution works nicely.

Another approach is using ggplot--note I have added an x-axis to the data.frame.

library(ggplot2)

dat<- data.frame(
  y = c(3.00,2.00,3.80,2.40,2.00),
 x = 1:5,    error = c(0.0,0.4,1.1,0.7,0.5))

limits <- aes(ymax = y + error, ymin=y - error)

p  <-  p  <-  ggplot(dat  , aes( x, y  )) + geom_point() +
                       geom_errorbar(limits)
p

____________________________________________________________
FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your desktop!



More information about the R-help mailing list