简体   繁体   中英

How do I make a grouped bar chart from frequency data in R

I have a table similar to the following which shows the number of samples which tested positive for viruses within different species:

Species Virus   NoTested    NoPositive  Prevalence  LowerCI UpperCI
1   1   100 46  0.46    0.4 0.5
2   1   80  23  0.29    0.2 0.3
3   1   96  3   0.03    0   0.1
1   2   133 45  0.34    0.2 0.5
2   2   23  10  0.43    0.3 0.5
3   2   75  16  0.21    0.1 0.3
1   3   88  24  0.27    0.2 0.3
2   3   94  12  0.13    0.1 0.2
3   3   65  34  0.52    0.4 0.6

I want to create a grouped bar graph such that I can show the proportion of positive samples for each species, in sets according to virus. I also want to add error bars showing confidence intervals.

I have tried doing this in ggplot using geom_bar(), but it gives me a really ugly stacked plot.

bar1<-ggplot(sppPrev3, aes(Species, Prevalence, colour=Virus))

see: this link a lot of info about graphing.

also, maybe try using barplot(t(dataframe), beside = TRUE)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM