0
dataToPlot = data.frame(
  Date = as.POSIXct(JMFINNTradingData$Transact.Time, format = "%Y/%m/%d %H:%M:%OS"),
  RollingPositionValues = JMFINNTradingData$SubTotal)

library('ggplot2')
myPlot = ggplot(dataToPlot, aes(y = dataToPlot$RollingPositionValues, x = dataToPlot$Date, group = 1))
myPlot + geom_line() + geom_path()

I have the following code with dates for the values of X and Numbers for the values of Y. For some reason the ordering of the Y axis is some random order and I cannot seem to influence this in any way. Image attached of how the Y axis looks like.

enter image description here

rawr
  • 20,481
  • 4
  • 44
  • 78
CodeGeek123
  • 4,341
  • 8
  • 50
  • 79

1 Answers1

0

Seems like your values are probably factors. Convert them to numerics and it should plot correctly:

aes(y = as.numeric(as.character(dataToPlot$RollingPositionValues)), x = dataToPlot$Date, group = 1)

edit: Forgot to add as.character() when converting a factor to a numeric.

Joel Carlson
  • 630
  • 3
  • 9
  • I tried this but the values this gives on the Y axis now is 0, 10 and 20. I am not sure how it came to this or how I can get rid of it. – CodeGeek123 Dec 04 '15 at 15:24
  • `as.numeric` on a `factor` will get you the levels number (try `as.numeric(factor(paste0(10:1, "")))`). you need to do `as.numeric(as.character(...))` – Cath Dec 04 '15 at 15:24
  • Hmm. Perhaps as.numeric(as.character( ... )) ? – Joel Carlson Dec 04 '15 at 15:26
  • Thanks but in doing that i make errors. Error in seq.default(from = best$lmin, to = best$lmax, by = best$lstep) : 'from' must be of length 1 In addition: Warning messages: 1: In eval(expr, envir, enclos) : NAs introduced by coercion 2: In eval(expr, envir, enclos) : NAs introduced by coercion 3: In eval(expr, envir, enclos) : NAs introduced by coercion – CodeGeek123 Dec 04 '15 at 15:33
  • 1
    It would be helpful if you could provide us with `RollingPositionValues`. Probably there is a character value somewhere in it, and you will need to remove the row containing it. – Joel Carlson Dec 04 '15 at 15:38
  • Hi Thanks. The values for Y are the one on the image above. I have taken away the blank value but the error still exists – CodeGeek123 Dec 04 '15 at 15:45
  • Before you use it in ggplot, convert the `RollingPositionValues` column to a numeric: `df$RollingPositionValues <- as.numeric(as.character(RollingPositionValues))` And the remove any rows with NA's using: `df <- df[complete.cases(df),]` – Joel Carlson Dec 04 '15 at 15:47