Error: Aesthetics must be either length 1 or the same as the data (891): x

ticket.first.char <- ifelse(data.combined$ticket == "", " ", substr(data.combined$ticket, 1, 1))

data.combined$ticket <- as.factor(ticket.first.char)


#> It has 16 levels as it supposed to define a ticket class by its unique first character:

levels(factor(data.combined$ticket))
 [1] "1" "2" "3" "4" "5" "6" "7" "8" "9" "A" "C" "F" "L" "P" "S" "W"

#> __________________________________________________________
> ggplot(data.combined[1:891,], aes(x = ticket.first.char)) +
+   geom_bar() +
+   ggtitle("Survivability by ticket.first.char") +
+   xlab("ticket.first.char") +
+   ylab("Total Count") +
+   ylim(0,350) +
+   labs(fill = "Survived")
#> The code displayed above is receiving the following error message 
Error: Aesthetics must be either length 1 or the same as the data (891): x

Could you provide an example of your data? It would be good to have a reproducible example: FAQ: What's a reproducible example (`reprex`) and how do I do one?

2 Likes

I agree a reproducible example would be very helpful. I will note the you set the label for the fill aesthetic but you do not define what variable sets that aesthetic. Have you left out part of the code?

1 Like

Great. Please respond and your (own, no false modesty) please mark the solution for the benefit of those to follow.