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]
我想创建一个可变宽度的箱线图,显示这些个体的分布,但从表中可以看出,NAs,离婚和分离的将是如此小的一组,它将难以辨认(和我怎样才能加入这些群体,创建一个显示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
答案 0 :(得分:0)
创建示例数据框
tblHoved <- data.frame(FAAR = rnorm(10),
SIVST = rep(c("e", "f", "g", "s", "ug"),2),
stringsAsFactors = FALSE)
tblHoved
# FAAR SIVST
# 1 0.22499630 e
# 2 1.10236362 f
# 3 0.02220001 g
# 4 0.19062022 s
# 5 0.05103136 ug
# 6 0.09280887 e
# 7 -0.70574835 f
# 8 0.39331232 g
# 9 0.24817094 s
# 10 0.66631994 ug
合并f和s
tblHoved$SIVST[tblHoved$SIVST %in% c("f","s")] <- "f+s"
tblHoved
# FAAR SIVST
# 1 0.22499630 e
# 2 1.10236362 f+s
# 3 0.02220001 g
# 4 0.19062022 f+s
# 5 0.05103136 ug
# 6 0.09280887 e
# 7 -0.70574835 f+s
# 8 0.39331232 g
# 9 0.24817094 f+s
# 10 0.66631994 ug