【发布时间】:2017-04-16 03:15:53
【问题描述】:
我有一个 983 obs 的表。 27 个变量;如果需要,可以提供数据,但我认为没有必要,因为下面的交叉表应该可以很好地总结它:
Kjønn Antall <> e f g s ug
Sex Count w d m s um
k 282 2 26 5 41 208
m 701 11 56 4 148 2 480
缩写(附英文翻译):
e[nkemann], f[raskilt], g[ift], s[eparert], ug[ift]
w[idow(er)], d[ivorced], m[arried], s[eparated], u[n]m[arried]
我想创建一个可变宽度的箱线图来显示这些人的分布,但从表格中可以看出,NA、离婚和分居的群体是如此之小,以至于难以辨认(并且毫无意义。我如何加入这些组,创建一个显示e、f+s、g 和ug 的箱线图?
我当前的代码:
# The basis for the boxplot
dBox_SexAge <- ggplot(data = tblHoved) +
geom_boxplot(
mapping = aes(colour = KJONN, x = KJONN, y = 1875-FAAR),
notch = TRUE,
lwd = .5, fatten = .125,
varwidth = TRUE
)
# Create the final boxplot
dBox_SexAgeMStat <- dBox_SexAge +
facet_grid(SIVST ~ .) +
coord_flip()
# Run it
dBox_SexAgeMStat
【问题讨论】:
标签: r ggplot2 grouping boxplot