Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6534057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:12:18+00:00 2026-05-25T10:12:18+00:00

I’m very new to R so this may be a simple question. I have

  • 0

I’m very new to R so this may be a simple question. I have a table of data that contains frequency counts of species like this:

  Acidobacteria              47
  Actinobacteria            497
  Apicomplexa                 7
  Aquificae                  16
  Arthropoda                 26
  Ascomycota                101
  Bacillariophyta             1
  Bacteroidetes           50279
  ...

There are about 50 species in the table. As you can see some of the values are a lot larger than the others. I would like to have a stacked barplot with the top 5 species by percentage and one category of ‘other’ that has the sum of all the other percentages. So my barplot would have 6 categories total (top 5 and other).

I have 3 additional datasets (sample sites) that I would like to do the same thing to only highlighting the first dataset’s top 5 in each of these datasets and put them all on the same graph. The final graph would have 4 stacked bars showing how the top species in the first dataset change in each additional dataset.

I made a sample plot by hand (tabulated the data outside of R and just fed in the final table of percentages) to give you an idea of what I’m looking for: http://dl.dropbox.com/u/1938620/phylumSum2.jpg

I would like to put these steps into an R script so I can create these plots for many datasets.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T10:12:18+00:00Added an answer on May 25, 2026 at 10:12 am

    Say your data is in the data.frame DF

    DF <- read.table(textConnection(
    "Acidobacteria              47
    Actinobacteria            497
    Apicomplexa                 7
    Aquificae                  16
    Arthropoda                 26
    Ascomycota                101
    Bacillariophyta             1
    Bacteroidetes           50279"), stringsAsFactors=FALSE)
    names(DF) <- c("Species","Count")
    

    Then you can determine which species are in the top 5 by

    top5Species <- DF[rev(order(DF$Count)),"Species"][1:5]
    

    Each of the data sets can then be converted to these 5 and “Other” by

    DF$Group <- ifelse(DF$Species %in% top5Species, DF$Species, "Other")
    DF$Group <- factor(DF$Group, levels=c(top5Species, "Other"))
    DF.summary <- ddply(DF, .(Group), summarise, total=sum(Count))
    DF.summary$prop <- DF.summary$total / sum(DF.summary$total)
    

    Making Group a factor keeps them all in the same order in DF.summary (largest to smallest per the first data set).

    Then you just put them together and plot them as you did in your example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I know there's a lot of other questions out there that deal with this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.