R 带3个分类变量的条形图
我有这样的数据:R 带3个分类变量的条形图,r,plot,R,Plot,我有这样的数据: data <- data.frame(Comp = factor(rep(2003:2004, each = 8)), Cat = rep(letters[1:4], 4), Type = rep(c('Free','Used'), each = 4), Count = trunc(rnorm(16,30,2))) 晶格中的数据: barchart(
data <- data.frame(Comp = factor(rep(2003:2004, each = 8)),
Cat = rep(letters[1:4], 4),
Type = rep(c('Free','Used'), each = 4),
Count = trunc(rnorm(16,30,2)))
晶格中的数据:
barchart(Count~interaction(Cat,Comp),groups=Type,data=data,auto.key=T,stack=T)
另一种分组方式,来自评论:
barchart(Count~Cat|factor(Comp),groups=Type,data=data,auto.key=T,stack=T)
类似地,在ggplot2
中:
ggplot(data, aes(x=interaction(Cat, Comp), y=Count, fill=Type)) +
geom_bar(position='stack', stat='identity')
要对附加变量(或两个)进行分组,可以使用facet\u wrap
或facet\u grid
ggplot(data, aes(x=Cat, y=Count, fill=Type)) +
geom_bar(position='stack', stat='identity') +
facet_wrap( ~ Comp)
快到了!您知道是否有任何选项可以对每个组件的Cat
条进行分组?像这样:barplot(vadeations,next=TRUE)
谢谢你,伙计!最后一个问题:在每个栏的中间有一个简单的方法来写这个值吗?同样的问题:你知道是否有任何选项可以将<代码> CAT<代码>中的每一个代码分组为每个代码> COMP < /代码>?像这样:barplot(vadeath,next=TRUE)
!最后一个问题:在每个栏的中间有一个简单的方法来写这个值吗?请尽量不要用越来越多的问题来修改问题:虽然没有得到回答,但乔兰的评论应该清楚地说明需要什么。