我正在使用化學資料集,其中有 11 種不同的化學物質,此處標記在 c1、c2、...c11 列下
我已經使用 制作了餅圖library(ggplot2)
,并且想用我的情節做兩件事。
- 如您在我的示例中所見,以水平方式(完成)顯示圖例中的所有變數,而不是將它們堆疊(未完成)。只有一條線會很棒。2行也可以接受。
- 將顏色更改為色盲友好
這是我們可以使用的假裝資料集,因此您可以看到我目前擁有的資料。我曾嘗試搜索“圖例邊距”以增加圖例的繪制區域,但無濟于事。
data <- read.delim("https://pastebin.com/raw/MS5GLAxa", header = T)
ggplot(data, aes(x="", y=ratio, fill=chemical))
geom_bar(stat="identity", width=1,position = position_fill()) facet_wrap(~treatment, nrow=1)
coord_polar("y", start=0)
theme_void(base_size = 20)
theme(legend.position=c(0.5, 1.2),legend.direction = "horizontal")
theme(plot.margin=unit(c(0,0,0,0), 'cm'))
這里的一些附帶獎金將能夠:
- 增加餅圖的大小(我相信我通過使邊距盡可能小來實作這一點)
- 餅圖有純色,圖表中沒有白線
uj5u.com熱心網友回復:
使用指南將行數設為 1,并使用帶有色盲友好調色板的 scale_fill_brewer。
ggplot(data, aes(x="", y=ratio, fill=chemical))
geom_bar(stat="identity", width=1,position = position_fill())
facet_wrap(~treatment, nrow=1)
coord_polar("y", start=0)
scale_fill_brewer(palette="Paired")
theme_void(base_size = 20)
theme(legend.position=c(0.5, 1.5),legend.direction = "horizontal",
plot.margin=unit(c(0,0,0,0), 'cm'))
guides(fill = guide_legend(nrow = 1)) # if required nrow = 2
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/491408.html