-1
拥有泰坦尼克号数据集,我绘制了年龄/性别与乘客分类的直方图。R + ggplot。绘制与父母数据相同图的儿童数据
str(titanic)
提供了以下数据
> 'data.frame': 714 obs. of 4 variables:
$ Survived: int 0 1 1 1 0 0 0 1 1 1 ...
$ Pclass : int 3 1 3 1 3 1 3 3 2 3 ...
$ Sex : chr "male" "female" "female" "female" ...
$ Age : num 22 38 26 35 35 54 2 27 14 4 ...
首先,我做了对旅游类男/女比例的曲线图。 >幸存者所有类别的比例 -
已通过
ggplot(data = titanic, aes(x = factor(Age), fill = factor(Sex))) +
geom_bar(position = "dodge", aes(y = (..count..)/sum(..count..))) +
facet_grid(. ~ Pclass) + scale_x_discrete(breaks=c(20,40,60)) +
ylab("Frequency") + xlab("Age") +
scale_fill_discrete(name = "Sex")
现在我想用相同图,但增加了额外的信息来完成。 例如,参加头等课程的20-30岁的存活女性的比例是多少。
我想看到它在相同的酒吧,即将每列分成两部分(幸存/未幸存)。
我可以用ggplot吗?如果是,如何?
你能提供代码从4D'Titanic'阵列去你'titanic' DF? – Axeman
你可能想用生存和'facet_grid(Sex〜P.class)'填充''。 – Axeman
您是否使用'facet_grid(。〜Pclass + Survived)'来实现您的目标? –