为了账号安全,请及时绑定邮箱和手机立即绑定

如何使用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 关注
  • 4355 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信