0

I want to add a few points to my ggplot, however when I add a few extra points it gives bugs and says 'Aesthetics must be either length 1 or the same as the data', what's wrong here and how to fix?

    ggplot(as.data.frame(AAPLtrans), mapping = aes(x = AAPLtrans$Date, y = AAPLtrans$Adj.Close, group=1)) + 
      geom_point(size=I(0.2)) + aes(colour = factor(DBOTfunc(num))) +
      geom_line() + 
      geom_point(aes(x=AAPL[P[num,][5],]$Date, y=AAPL[P[num,][5],]$Adj.Close), colour="black", shape=1, size=3) + 
      geom_point(aes(x=AAPL[P[num,][4],]$Date, y=AAPL[P[num,][4],]$Adj.Close), colour="black", shape=1, size=3) + 
      geom_point(aes(x=AAPL[P[num,][3],]$Date, y=AAPL[P[num,][3],]$Adj.Close), colour="black", shape=1, size=3) + 
      geom_point(aes(x=AAPL[P[num,][2],]$Date, y=AAPL[P[num,][2],]$Adj.Close), colour="black", shape=1, size=3)
austensen
  • 2,857
  • 13
  • 24
dome some
  • 479
  • 7
  • 22
  • I'm confused. Do the points come from a different data set or the same data set? – Ryan Morton Jun 02 '17 at 17:54
  • Maybe this is similar to what you want to do: https://stackoverflow.com/questions/31069324/adding-points-from-other-dataset-to-ggplot2 – Ryan Morton Jun 02 '17 at 17:56
  • Well, I guess as the error message tells you: the mapped values inside aes have to be vectors of length 1 or of the number of rows of as.data.frame(AAPLtrans). And that seems not to be the case. Maybe you build subsets somwhere and inherit the global aes mappings inside `ggplot`. Hard to tell - you might want to provide a minimal reporducible example as asked by the R tag (hover over it). – lukeA Jun 02 '17 at 18:16
  • Furtheremore, there should not be any $s in within the aes clause. – CMichael Jun 02 '17 at 18:18

2 Answers2

1

One possibility is that you have inadvertently misspelled one of the names of your variables in the aes mapping . Possibly an upper/lower case difference? This will create a length mismatch, with the difference being the # of columns misspelled.

Michael Tuchman
  • 332
  • 3
  • 12
0

You have a geom_line() with no aes wrapper, could that be it?

Ken Wallace
  • 2,261
  • 2
  • 13
  • 13