亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用ggplot2上的標識控制堆積條形圖的順序

如何使用ggplot2上的標識控制堆積條形圖的順序

米脂 2019-12-03 10:13:55
使用這個假人 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")


查看完整回答
反對 回復 2019-12-03
  • 3 回答
  • 0 關注
  • 4594 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號