Reputation: 289
original data
a = as.data.frame((cbind(c('a','a','b','a'),c(0,0,1,1))))
a
V1 V2
1 a 0
2 a 0
3 b 1
4 a 1
plot a bar
ggplot(data=a,aes(x=V1,fill=factor(V1))) + geom_bar()
then i got this
but if i convert the data to this
a
V1 V2 V2.number
1 a 0 2
2 a 1 1
3 b 1 1
i do this is becuse data is too big,i have to summary it
how could i get a picture like before?
Upvotes: 0
Views: 132
Reputation: 98449
Use column V2.number
as y values and add argument stat="identity"
to geom_bar()
.
ggplot(a,aes(V1,V2.number,fill=factor(V2)))+geom_bar(stat="identity")
Upvotes: 0
Reputation: 132706
Use stat_identity
:
ggplot(data=a,aes(x=V1, y=V2.number, fill=factor(V2))) +
geom_bar(stat="identity")
Upvotes: 1