使用這個假人 data.framets <- data.frame(x=1:3, y=c("blue", "white", "white"), z=c("one", "one", "two"))我嘗試在頂部繪制“藍色”類別。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")反轉顏色,但頂部仍給我“白色”。我怎樣才能在頂部獲得“藍色”?
3 回答

幕布斯6054654
TA貢獻1876條經驗 獲得超7個贊
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 關注
- 4594 瀏覽
添加回答
舉報
0/150
提交
取消