Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 位置_道奇()不道奇_R_Ggplot2 - Fatal编程技术网

R 位置_道奇()不道奇

R 位置_道奇()不道奇,r,ggplot2,R,Ggplot2,我想回避我的酒吧的位置,但它根本不这样做,我真的不知道为什么 这是我的代码: y = c(10.3,12.3,2.3,4.5,6,7.8) df <- data.frame( video = factor(c(1, 2, 3, 4, 5, 6)), ERDERS = y, group = factor(c(1, 1, 2, 2, 3, 3))) p1 <- ggplot(df, aes(fill=factor(group), y= ERDERS, x

我想回避我的酒吧的位置,但它根本不这样做,我真的不知道为什么

这是我的代码:

 y = c(10.3,12.3,2.3,4.5,6,7.8)
 df <- data.frame(
   video = factor(c(1, 2, 3, 4, 5, 6)),
   ERDERS = y,
   group = factor(c(1, 1, 2, 2, 3, 3)))

     p1 <- ggplot(df, aes(fill=factor(group), y= ERDERS, x= video))
   p1 <- p1 + geom_bar(color = "gray60", stat="identity", position = position_dodge()) +               
   scale_y_continuous(limits=c(-3, 21), name = "Activity[%]")+                                  # Y-Axis scaling + title
   scale_x_discrete(name = "VIDEO", labels=c("1", "2", "3", "4", "5", "6"))+
   theme_bw()
y=c(10.3,12.3,2.3,4.5,6,7.8)

df我还是有点困惑,但也许你在找这个

p1 <- ggplot(df, aes(y = ERDERS, x = group, fill = video))
p1 <- p1 + geom_bar(color = "gray60", stat = "identity", position = 'dodge') +
  scale_y_continuous(limits=c(-3, 21), name = "Activity[%]") +
  scale_x_discrete(name = "GROUP", labels=c("1", "2", "3", "4", "5", "6")) +
  theme_bw()

p1您有六个数据点和六个条,到底应该回避什么?始终应该回避其中两个,即根据因子组。那么,应该有一种方法仍然可以对视频1/2(组1)、3/4(组2)和视频5/6(组3)进行分组。如果我有6个不同的视频,我想绘制它们的值,我需要6个不同的x值。嗯,但是这里的结果和我用示例代码得到的结果没有什么不同,是吗?它们在我看来确实不同。添加了情节。啊,我错了!有些东西坏了,必须重新启动R,现在它正在工作!这就是我一直在寻找的,虽然我曾希望有一个解决方案来保持旧的x轴…谢谢!完美的非常感谢!:)事实上,这并不完全是我一直在寻找的,但看起来好多了!
p3 <- ggplot(df, aes(y = ERDERS, x = video)) + 
  facet_wrap(~ group, scales = 'free_x')
p3 <- p3 + geom_bar(color = "gray60", stat = "identity", position = 'dodge') +
  scale_y_continuous(limits=c(-3, 21), name = "Activity[%]") + theme_bw() + 
  ggtitle('Groups')