相互に排他的ではない他のいくつかの特性を持つ変数を含むデータ セットがあります。これがデータです。
df <- structure(list(cont1 = structure(c(2L, 2L, 4L, 1L, 2L, 3L, 2L, 4L, 4L, 1L, 2L, 2L, 4L, 1L, 1L, 2L, 2L), .Label = c("Africa", "Asia", "Europe", "LAC"), class = "factor"), SIDS = structure(c(2L, 1L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("No", "SIDS"), class = "factor"), LDC = structure(c(2L, 1L, 2L, 1L, 2L, 2L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("LDC", "No"), class = "factor")), .Names = c("cont1",
"SIDS", "LDC"), class = "data.frame", row.names = c(NA, -17L))
したがって、それを長い形式df.m <- melt(df, id.vars = c("cont1"))
にすると、プロットを作成できますがggplot2
、プロット内のすべての NA を取得できます。それらを除外すると、カテゴリの 1 つにより多くの NA があるため、比率が歪んでしまいます。
ggplot(df.m, aes(x = cont1, fill = value)) + geom_bar()
ggplot(df.m[df.m$value != "No",], aes(x = cont1, fill = value)) + geom_bar()
NAが比率を歪めずに、塗りつぶしとして変数cont1
の棒グラフを作成する方法はありますか? value
つまり、フィルインに別の長さを使用できggplot2
ますか?