cottinR
cottinR

Reputation: 181

Frequency plot for different categories

I have this input:

structure(list(Topic = structure(c(1L, 2L, 3L, 1L, 2L, 3L), .Label = c("1", 
"2", "3"), class = "factor"), Sex = structure(c(1L, 1L, 1L, 2L, 
2L, 2L), .Label = c("Female", "Male"), class = "factor"), Count = c(2L, 
15L, 23L, 7L, 20L, 34L)), class = "data.frame", row.names = c(NA, 
-6L))

and I try this code:

ggplot(data=dat, aes(x=Topic, y=Sex, fill=Sex)) + geom_bar(stat="identity")

However the problem is it shows the same proposion for every topic

How is it possible to make the plot like this one?

Upvotes: 0

Views: 148

Answers (1)

Maël
Maël

Reputation: 51974

What about this?

dat %>% 
  ggplot(aes(Topic, Count)) + 
  geom_bar(aes(fill = Sex), stat = "identity", position = "dodge")

enter image description here

Upvotes: 1

Related Questions