Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

What about this?

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

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading