Last answered:

09 Dec 2021

Posted on:

09 Dec 2021


My fill = Survived command is not working.

Hello! My fill = Survived command is not working. It was working when it was fill = Sex, but when I switch it to Survived, the graph doesn't show the different colors for Survived and Dead, it just stays gray. I can't seem to find what the problem is, especially because my code is similar to yours! Do you have any idea of what the problem might be?

1 answers ( 0 marked as helpful)
Posted on:

09 Dec 2021


Before you plot your data, you need to make sure that the factors according to which you are setting your aesthetics, are actually factors in your data. I am sure you already know how to do that, but just in case, here's how I'd do it:

# Load your data first
# And then tell R some of your variables should be factors with the as.factor() function
file$Sex <-
file$Survived <- as.factor(file$Survived)

If you then execute your code, just as it is, you should be getting the color assignments

Submit an answer