Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.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 ggplot2中的分组条形图_R_Ggplot2_Bar Chart - Fatal编程技术网

R ggplot2中的分组条形图

R ggplot2中的分组条形图,r,ggplot2,bar-chart,R,Ggplot2,Bar Chart,我想复制这个图(在组之间使用镶嵌面) (如中所做的镶嵌面) 这是我的尝试: library (ggplot2) data<- data.frame( d = rep(LETTERS[21:26], 10), val = rnorm (60), c = rep(LETTERS[1:10], each = 6) ) ggplot(data, aes(c, val)) + geom_bar(stat = 'identity', aes(fill = val), position

我想复制这个图(在组之间使用镶嵌面) (如中所做的镶嵌面) 这是我的尝试:

library (ggplot2)
data<- data.frame(
  d = rep(LETTERS[21:26], 10),
  val = rnorm (60),
  c = rep(LETTERS[1:10], each = 6)
)

ggplot(data, aes(c, val)) + 
 geom_bar(stat = 'identity', aes(fill = val), position = "dodge") +
 facet_grid(data[, 1] ~ .)
库(ggplot2)

数据我认为您不需要
facet\u grid()
,只需填写
'd'

ggplot(data, aes(c, val)) +
  geom_bar(stat = 'identity', aes(fill = d), position = "dodge")


根据OP的评论,我们也可以使用
facet\u网格(cols=vars(d))


我需要水平刻面,我无法在excel中复制。@Bifoan编辑了我的答案。希望这有帮助。
ggplot(data, aes(c, val)) + 
  geom_bar(stat = 'identity', aes(fill = val), position = "dodge") +
  facet_grid(cols = vars(d)) # or facet_grid(. ~ d)