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)