使用這個(gè)假人 data.framets <- data.frame(x=1:3, y=c("blue", "white", "white"), z=c("one", "one", "two"))我嘗試在頂部繪制“藍(lán)色”類(lèi)別。ggplot(ts, aes(z, x, fill=factor(y, levels=c("blue","white" )))) + geom_bar(stat = "identity")在上面給我“白色”。和ggplot(ts, aes(z, x, fill=factor(y, levels=c("white", "blue")))) + geom_bar(stat = "identity")反轉(zhuǎn)顏色,但頂部仍給我“白色”。我怎樣才能在頂部獲得“藍(lán)色”?
3 回答

幕布斯6054654
TA貢獻(xiàn)1876條經(jīng)驗(yàn) 獲得超7個(gè)贊
group在ggplot()通話中使用美感。這樣可以確保所有層以相同的方式堆疊。
series <- data.frame(
time = c(rep(1, 4),rep(2, 4), rep(3, 4), rep(4, 4)),
type = rep(c('a', 'b', 'c', 'd'), 4),
value = rpois(16, 10)
)
ggplot(series, aes(time, value, group = type)) +
geom_col(aes(fill = type)) +
geom_text(aes(label = type), position = "stack")
- 3 回答
- 0 關(guān)注
- 4593 瀏覽
添加回答
舉報(bào)
0/150
提交
取消