I've grouped some Data about the titanic the following way:
priceMutate <- mutate(titanic, PriceGroup = ifelse (Fare < 51,
'0 - 50',
ifelse(Fare >=51 & Fare < 101,
'51-100',
ifelse(Fare >= 101 & Fare < 151,
'101-150',
ifelse(Fare >= 151 & Fare < 201,
'151-200',
ifelse(Fare >= 201 & Fare < 251,
'201-250',
ifelse(Fare >= 251 & Fare < 301,
'251-300',
ifelse(Fare >= 301 & Fare < 351,
'301-350',
ifelse(Fare >= 351 & Fare < 401,
'351-400',
ifelse(Fare >= 401 & Fare < 451,
'401-450',
ifelse(Fare > 450,
'451+','?')))))))))))
"Fare" is the price payed for a ticket for the titanic. I've chosen steps of 50$.
Now here is my problem:
I've made a plot that shows the chance of survival regarding the price of the tickets:
output$ex15 <- renderPlot({
ggplot(priceMutate,
aes(x = PriceGroup,
fill = Status)) +
geom_bar(position = "fill")+
ggtitle("Überlebenschancen nach Preis des Tickets (gruppiert)")+
theme(plot.title = element_text(size = 16))+
scale_fill_manual(values = c("grey24", "snow"))+
labs(y= "Anzahl")
})
However this plot mixes up the groups I made and does not show the "?" for the not-available data!
Can anyone see a problem/mistake that I've made?
Here is a link to my dataset: https://drive.google.com/file/d/1xsIfkv1464etX23O0J9y35CviK0mKYQl/view?usp=sharing
Thank you a lot :)