0

conditionally assign error bar to plot using geom_error bar from GGPLOT.

UPPER ERROR BAR - LOG SCALE

if (df$scl == 'lg' )  {

          p <<- p+ geom_errorbar(data=summ,aes(ymin=avg-0, ymax=avg+sd), width=.2,
                position=position_dodge(.9))      

} # UPPER ERROR BAR - LOG SCALE ENDS

UPPER ERROR BAR - LOG SCALE

if (df$scl == 'lg' )  {

          p <<- p+ geom_errorbar(data=summ,aes(ymin=avg-0, ymax=avg+sd), width=.2,
                position=position_dodge(.9))      

} # UPPER ERROR BAR - LOG SCALE ENDS

Error bar is not assigned even though condition is true.

> dput(head(df, 20))
structure(c("function (x, df1, df2, ncp, log = FALSE) ", "{", 
"    if (missing(ncp)) ", "        .Call(C_df, x, df1, df2, log)", 
"    else .Call(C_dnf, x, df1, df2, ncp, log)", "}"), .Dim = c(6L, 
1L), .Dimnames = list(c("1", "2", "3", "4", "5", "6"), ""), class = 
"noquote")
kamal
  • 89
  • 1
  • 7
  • Please read [How to make a great R reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). 1) Why repeat the same code? 2) What is `p`? 3) Why do you assign with `<<-`? 4) Can you post sample data and the code that produced `p`? Please edit **the question** with the output of `dput(df)`. Or, if it is too big with the output of `dput(head(df, 20))`. – Rui Barradas Aug 25 '19 at 13:42
  • p is GGPLOT object.<<- is global object. – kamal Aug 25 '19 at 13:45
  • 1
    Yes, I know that `p` is a ggplot object, what I'm asking is how it was created. And no, `<<-` is not a global *object*, it's global *assignment*. You only need it to assign in another evaluation frame. For instance, if you are in a function and want to change the object in the `.GlobalEnv`. This does not seem to be the case. Anyway, please post context: code and data. – Rui Barradas Aug 25 '19 at 13:50
  • p is inside nested function. i want it to be available for for subsequent functions. – kamal Aug 25 '19 at 13:52
  • by the way, plot is generated. so p is existing. only issue is errorbar is not added, even though mean and sd is there in input df. – kamal Aug 25 '19 at 13:54
  • My point is that as is the code is not reproducible. We cannot see what is wrong if we do not know the data and a minimal code example to recreate `p`. If the data (and code) are private, make up an example that can reproduce the error with, for instance, the random number generators R has. As long as the data structure is the same, the error will be reproduced. – Rui Barradas Aug 25 '19 at 13:57
  • input df is added now. – kamal Aug 25 '19 at 13:57
  • 1
    OK, thanks! What you have is a names conflict: you have posted the object df as in the probability density function of the F distribution, see help('df'). Sometimes R users choose names of functions that already exist and conflicts might occur. That is the case here. – Rui Barradas Aug 25 '19 at 14:10
  • Thanks Rui. tried again. some places i had assigned <<- , some places <-. that was the problem. uniformly did <<- . now working. Thank you for quick response. – kamal Aug 25 '19 at 14:15
  • `fortunes::fortune("<<-")`: "I wish <<- had never been invented, as it makes an esoteric and dangerous feature of the language *seem* normal and reasonable. If you want to dumb down R/S into a macro language, this is the operator for you. -- Bill Venables R-help (July 2001)" – IRTFM Aug 25 '19 at 20:14

0 Answers0