ISAAKiel / oxcAAR

R Package - Interaction with Oxcal
GNU General Public License v2.0
21 stars 4 forks source link

Improving the plot output #7

Closed MartinHinz closed 7 years ago

MartinHinz commented 7 years ago

Three things to do here (?):

nmueller18 commented 7 years ago

It seems that R cannot draw error ranges out of the box. Here is a workaround derived from stackoverflow:

plot(x, avg, ylim=range(c(avg-sdev, avg+sdev)), pch=19, xlab="Measurements", ylab="Mean +/- SD", main="Scatter plot with std.dev error bars" ) hack: we draw arrows but with very special "arrowheads" arrows(x, avg-sdev, x, avg+sdev, length=0.05, angle=90, code=3)

Another solution with ggplot2:

qplot(x,y)+geom_errorbar(aes(x=x, ymin=y-sd, ymax=y+sd), width=0.25)

MartinHinz commented 7 years ago

@nmueller18, please try following snipped, and let me know if this fits your expectations:

library(oxcAAR)
quickSetupOxcal()
this_date <- oxcalCalibrate(5000,20)

plot(this_date)

plot_calcurve <- function(from=-4000, to=-3600){
  calcurve <- read.table("OxCal/bin/intcal13.14c", header = F, sep = ",")
  calcurve$V1 <- 1950 - calcurve$V1
  calcurve <- subset(calcurve, V1 > from & V1 < to)
  plot(calcurve$V1, calcurve$V2, type="l",xlim=c(from,to))
  sigma_poly <- data.frame(x=c(calcurve$V1,rev(calcurve$V1)),
                           y = c(calcurve$V2+calcurve$V3, rev(calcurve$V2-calcurve$V3) ))
  polygon(sigma_poly$x,sigma_poly$y, col=rgb(0.2, 0.2, 0.2,0.2), border = F )
}

plot_calcurve()

full_one_sigma_range <- c(min(this_date$`1`[['sigma_ranges']]$one_sigma$start),max(this_date$`1`[['sigma_ranges']]$one_sigma$end))

arrows(mean(full_one_sigma_range),
       this_date$`1`$bp - this_date$`1`$std,
       mean(full_one_sigma_range),
       this_date$`1`$bp + this_date$`1`$std,
       length=0.05, angle=90, code=3)

arrows(min(full_one_sigma_range),
       this_date$`1`$bp,
       max(full_one_sigma_range),
       this_date$`1`$bp,
       length=0.05, angle=90, code=3)
nmueller18 commented 7 years ago

There seems to be missing something. The function "plot_calcurve" is defined, but not invoked. As it is now, the snippet does not work. :-(

MartinHinz commented 7 years ago

Edited snippet. Should work now, could not test because my Arch is currently caught in dependency hell regarding R :-(

nmueller18 commented 7 years ago

This does work now! (only plot_calcurve()was missing). With many dates, the horizontal bar might be too much because of overlappings.

MartinHinz commented 7 years ago

Forked an independent issue #12 for that. Forked also an independent issue #13 for ggplot output.

Anything else we should take care of?

MartinHinz commented 7 years ago

@ISAAKiel/oxcaar-development, please check if plot outputs are now ok for release, or else comment with suggestions. Thanks!

nevrome commented 7 years ago

I would like to have rug marks for the calcurve plot. If I get your OK, I can try to implement this myself.

nmueller18 commented 7 years ago

Is the option to exclude the horizontal bar already implemented? In my opinion the vertical bar should be adjusted in size as well when changing the sigma-range.

MartinHinz commented 7 years ago

@nevrome, sure thing, thanks. Btw, could you add an Option to skip the horizontal bar, like me and @nmueller18 already discussed, an I forgot. Currently mobile, no way to code. Thanks!

nevrome commented 7 years ago

@nmueller18 Please check, if this is ok. Error bars confuse me all the time.