dome some
dome some

Reputation: 479

Aesthetics must be either length 1 or the same as the data

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)

Upvotes: 0

Views: 4690

Answers (2)

Michael Tuchman
Michael Tuchman

Reputation: 352

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.

Upvotes: 1

Ken Wallace
Ken Wallace

Reputation: 2401

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

Upvotes: 0

Related Questions