「ggplot」を使用して積み上げ棒プロットを作成し、移植実験からの核型 (分子) の結果を表示しました。各パネルは場所を表し、x 軸はさまざまな基質で、y 軸はパーセンテージです。 3つの核型のそれぞれ。
Stack Overflow からの質問と回答の例をいくつか調べましたが、次の方法がわかりません。
- 積み上げられたバーの各セクション内の値を中央に配置します (小数点以下 2 桁に丸める必要があります)。現在は、それらを上からオフセットしています。
- 凡例のテキストを "BB" からギリシャ語の "lower alpha, lower alpha" に、"BD" をギリシャ語の "lower alpha, lower beta" に、"DD" をギリシャ語の "lower beta, lower beta" に変更する方法。
これが生成するプロットのコピーを含むサンプル データとコードを次に示します。
Karotype.Data <- structure(list(Location = structure(c(1L, 1L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 4L, 4L, 1L, 1L, 1L, 4L, 2L, 1L, 2L, 1L, 2L, 2L, 2L, 2L, 2L), .Label = c("Kampinge", "Kaseberga", "Molle", "Steninge"), class = "factor"), Substrate = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 3L, 4L, 2L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 3L, 2L, 1L, 4L, 2L), .Label = c("Kampinge", "Kaseberga", "Molle", "Steninge"), class = "factor"), Karyotype = structure(c(1L, 3L, 4L, 1L, 3L, 3L, 4L, 4L, 4L, 3L, 1L, 4L, 3L, 4L, 2L, 3L, 1L, 4L, 3L, 2L, 4L, 3L, 4L, 2L, 3L), .Label = c("", "BB", "BD", "DD"), class = "factor")), .Names = c("Location", "Substrate", "Karyotype"), row.names = c(135L, 136L, 137L, 138L, 139L, 165L, 166L, 167L, 168L, 169L, 236L, 237L, 238L, 239L, 240L, 326L, 327L, 328L, 329L, 330L, 426L, 427L, 428L, 429L, 430L), class = "data.frame")
z.counts <- Karotype.Data %>%
group_by(Location,Substrate,Karyotype) %>%
summarise(Frequency=n())
z.freq <- z.counts %>% filter(Karyotype != '') %>%
group_by(Location,Substrate) %>%
mutate(Percent=Frequency/sum(Frequency))
z.freq
ggplot(z.freq, aes(x=Substrate, y=Percent, fill=Karyotype )) +
geom_bar(stat="identity") +
geom_text(aes(label = Percent), size = 5, vjust = 1, position = "stack") +
facet_wrap(~ Location, ncol=2) +
scale_y_continuous(name="Percentage") +
theme(strip.text.x = element_text(colour="black", size=20, face="bold"),
axis.title.x = element_text(colour="black", size=20, face="bold", vjust=-0.5),
axis.text.x = element_text(colour="black", size=18),
axis.title.y = element_text(colour="black", size=20,face="bold", vjust=1),
axis.text.y = element_text(colour="black", size=18),
legend.title = element_text(colour="black", size=20, face="bold"),
legend.text = element_text(colour="black", size = 18),
legend.position="bottom")