0

I am using ggplot to plot some data (x='filt' and y='flux' (shown in the code below) along with the lower and upper symmetric error bars, which are provided in a different file.
The problem is that some of the error values correspond to "-1", which are actually the upper limits. I am totally clueless about drawing an upper limit using ggplot.

So, far I just replaced -1 by 0.0, which lets me plot the other error bars, and here is my program :

 skipped few lines

data file with filter-flux data :

data_flux<-melt(dflux,id="filt",variable.name ="objs",value.name="flux")

datafile with error information :

d2[d2==-1.0]<-0.0  # upper limits
data_err<-melt(d2,id="filt",variable.name = "objs",value.name="err_flux")

combined data:

finaldata<-cbind(data_flux,data_err)

Plotting :

g<-ggplot(finaldata,aes(x=filt,y=log10(flux),color=objs))
gf1<-g+geom_point(size=2,alpha=0.8,pch=15)+theme_bw()
gf<-gf1+geom_errorbar(aes(ymax=log10(flux)+err_flux,ymin=log10(flux)-err_flux),size=0.5,color="darkgrey")
gff<-gf+xlab("wavelength")+ylim(0,5)+geom_smooth(method="loess",se=FALSE)
gff+scale_color_hue(l=10, c=75)

The 'geom_error' function plots both the upper and lower limits and I could use an "if" condition to filter out the data, for which only the upper limits are provided, but the question is again about plotting inside the ggplot.

Any help or suggestions would be greatly appreciated.

Example data:
index filt objs flux filt objs err_flux
1 4590 obj1 1005.448892 4590 errobj1 0.0401
2 6220 obj1 1420.626789 6220 errobj1 0.0392
3 7640 obj1 1855.581355 7640 errobj1 0.0432

................................................

17 8989 obj2 246.899380 8989 errobj2 0.0608
18 12561 obj2 381.311585 12561 errobj2 0.0866
19 16467 obj2 657.233966 16467 errobj2 0.0982
20 21512 obj2 949.642188 21512 errobj2 0.1516
21 2030 obj2 9.838299 2030 errobj2 0.0000
22 2253 obj2 17.097003 2253 errobj2 0.0000
23 2612 obj2 14.754347 2612 errobj2 0.0000
24 3470 obj2 14.890868 3470 errobj2 0.0000

I would like to draw the upper limits on my plot (attached) for the points, where "err_flux==0.0". i.e. for the "obj2" in the plot, I would like to plot arrows pointing downwards from the 4 leftmost points.

enter image description here

Cactus
  • 27,075
  • 9
  • 69
  • 149
akaur
  • 389
  • 1
  • 6
  • 22
  • 1
    Perhaps you can show some example data to clarify your question. [See here.](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – Axeman Oct 12 '15 at 18:33
  • Done ! I hope this helps. – akaur Oct 12 '15 at 19:31

1 Answers1

0

Are you trying to set the axis limits for the y-axis?

Try expand_limits()

It works as a way to change the x and y axis without disturbing the ylimits too much.

expand_limits(y=-1)
Jaap
  • 81,064
  • 34
  • 182
  • 193
  • sorry, I was not clear in the question. I want the upper limits as errors for my data, which are typically drawn as arrows pointing downwards from the respective data points. – akaur Oct 12 '15 at 19:33