uncool
uncool

Reputation: 2703

How to make max() take variable as it's argument

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.

Upvotes: 0

Views: 79

Answers (1)

rbatt
rbatt

Reputation: 4807

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.

Upvotes: 1

Related Questions