Warning: package 'ggplot2' was built under R version 4.4.3
library(dplyr)p <- titanic_train %>%mutate(Pclass =factor(Pclass, levels=c(3, 2, 1), label =c("三等艙", "二等艙", "頭等艙"))) %>%mutate(Survived =factor(Survived)) %>%ggplot(., aes(x = Pclass, fill = Survived)) +geom_bar(position ="fill") +# Stacked bar plotfacet_wrap(~ Sex) +# Separate by genderlabs(title ="Survival Rate by Pclass and Sex",x ="Pclass (Passenger Class)",y ="Proportion of Survivors",fill ="Survived" ) +scale_fill_manual(values =c("#888", "red"), labels =c("Did not survive", "Survived")) +theme_minimal() +theme(text =element_text(family ='黑體-繁 中黑')) # 設定顯示中文字(Mac)p
Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family
not found in Windows font database
Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family
not found in Windows font database
Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database
Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database
Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family
not found in Windows font database
Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database
Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database
Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database
Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database