R/UpdateGraph.R

Defines functions GetGraphText UpdateGraph ylab

Documented in UpdateGraph ylab

# NB xlab() and ylab() are also functions in ggplot2; 
# this BrailleR  implementation is inconsistent with ggplot2.

main = xlab = ylab = function(graph, label=NULL){
    arg = as.character(match.call()[[1]])
    Obj = as.character(match.call()[["graph"]])
    if(any(class(graph)=="Augmented")){
        if(is.null(label)){
            Out = .GetGraphText(graph, arg)
            return(Out)
        } else {
            Out = .UpdateGraph(graph, label, arg)
            assign(Obj, Out, parent.frame())
            return(invisible(Out))
        }
    }
}


update.scatterplot = update.tsplot = update.fittedlineplot = UpdateGraph = function(object, ...){
      MC <- match.call(expand.dots = TRUE)
      ParSet = (as.list(MC))[-c(1,2)]
      Obj = as.character(match.call()[["object"]])
      Out = object
# now sift ExtraArgs from ParSet and update them
# now sift pars from ParSet and update them
      assign(Obj, Out, parent.frame())
      return(invisible(Out))
}


.UpdateGraph = function(graph, label, arg){
    graph$"ExtraArgs"[[arg]] = label
    if(any(class(graph)=="ggplot")){
        arg = .ggplotLabelNames[arg]
        graph$labels[[arg]] = label
    }
    print(graph) # is actually plot() except for histograms
    return(invisible(graph))
}

.GetGraphText = function(graph, arg){
    return(invisible(graph$"ExtraArgs"[[arg]]))
}

.ggplotLabelNames = c(main="title", sub="subtitle", xlab="x", ylab="y")

Try the BrailleR package in your browser

Any scripts or data that you put into this service are public.

BrailleR documentation built on Aug. 10, 2018, 5:04 p.m.