我分析了多个相关问题,但无法解决问题。
以下是我的数据,名为fam
:
structure(list(familiarity = structure(c(1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L), .Label = c("familiar", "not familiar",
"not sure"), class = "factor"), idiom = structure(c(7L, 8L, 1L,
5L, 4L, 9L, 3L, 6L, 2L, 6L, 2L, 3L, 4L, 9L, 7L, 8L, 1L, 5L, 9L,
2L, 3L, 4L, 6L, 7L, 8L, 1L, 5L), .Label = c("be in the same boat",
"beat one’s chest", "chew the fat", "just around the corner",
"kick the bucket", "left hanging in the air", "sweep sth under the carpet",
"take the plunge", "tighten one’s belt"), class = "factor"),
frequency = c(11L, 11L, 11L, 11L, 10L, 8L, 8L, 7L, 6L, 4L,
3L, 2L, 1L, 1L, 0L, 0L, 0L, 0L, 2L, 2L, 1L, 0L, 0L, 0L, 0L,
0L, 0L)), .Names = c("familiarity", "idiom", "frequency"), class = "data.frame",
row.names = c(NA, -27L))
我想出了如何进行堆积条形图。这就是我得到的:
到目前为止,这是我的代码:
ggplot(data = fam, aes(x = idioms, y = frequency, fill = familiarity, width = 0.5)) +
geom_bar(stat = 'identity') +
coord_flip() +
scale_fill_manual(values = c('limegreen', 'purple', 'red1')) +
theme(axis.title.y = element_blank(),
axis.title.x = element_text(size = 10),
axis.text.x = element_text(size = 10),
axis.text.y = element_text(size = 10),
legend.text = element_text(size_10),
text = element_text(size = 10),
plot.margin = unit(c(0.3, 0.5, 0.3, 0.8), 'cm')) +
scale_y_continuous(breaks = pretty_breaks()) +
labs(y = "number of responses") +
labs = (fill = "")
我希望得到一个关于熟悉度的有序堆积条。粗略地说,我希望首先得到最高的熟悉度分数(绿色条),然后熟悉'熟悉'并且不确定',然后熟悉','不确定','不熟悉'。基本上,质量下降。
我很感激任何建议。