0

In setting the scales of my ggplot, I need to specify max and min values.

Now everything works fine if I specify the path directly (e.g x$column), but I would like it to take an argument containing the path, how can this be achieved?

Code

SMAcolName  <- colnames(ov.indicators)[grep("SMAPrice", names(ov.indicators))]
SMAsourceName  <- paste0("ov.indicactors$", SMAcolName)

    line.SMAsqrmPrice  <- ggplot(data = fortify(ov.indicators), aes_string( x = "published", y = SMAcolName )) + 
      geom_line() + 
      scale_y_continuous(breaks = c(seq(10000, max(SMAsourceName, na.rm = TRUE), by = 5000) )) +

The above code gives an error, but demonstrates what I'm trying to achieve.

mts
  • 2,160
  • 2
  • 24
  • 34
uncool
  • 2,613
  • 7
  • 26
  • 55
  • 2
    use `get(..., envir= "ov.indicators")`. The way you're attempting passes a character string, not a variable name that needs to be interpretted – alexwhitworth Aug 09 '15 at 20:58
  • 2
    I think `"SMAsourcename"` is a string. I don't have a data.frame named ov.indicators, so I won't check. Please give a [minimal WORKING example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – N8TRO Aug 09 '15 at 20:59

1 Answers1

1

I think you want max(ov.indicators[,"SMAcolName"], na.rm=TRUE).

The trick here is that you don't need to use the $ notation. I'm assuming that ov.indicators is a data.frame or a matrix (or a 2D array). That assumption is based on your use of colnames.

rbatt
  • 4,677
  • 4
  • 23
  • 41