[英]Dodge not working in ggplot geom_col
I am going crazy with this, I know I am just doing something simple wrong.我快要疯了,我知道我只是在做一些简单的错误。
All I want to do is to get this simple plot to go side by side to evaluate paired data.我想要做的就是让这个简单的图并排来评估配对数据。 position = "dodge is not working position = "闪避不起作用
require(tidyverse)
mine = tibble(
x = seq(1,36,1)
y = rnorm(36),
z = rexp(36)
)
ggplot(data = mine,aes(x,y)) +
geom_col(colour = "red") +
geom_col(aes(x,z),colour="white")
I am either putting it in the wrong place, or my data is not set up correctly, but this should be simple!!我要么把它放在错误的地方,要么我的数据设置不正确,但这应该很简单!!
You need to prepare the data in a tidy way.您需要以整洁的方式准备数据。 Then you can use fill to separate the variables:然后你可以使用 fill 来分隔变量:
require(tidyr)
dp <- gather(mine, Var,Value,-x)
ggplot(data = dp,aes(x,Value, fill=Var)) +
geom_col( position="dodge") +
scale_fill_manual(values=c("red","white"))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.