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

  • SEARCH
  • Home
  • 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 8771155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:42:55+00:00 2026-06-13T17:42:55+00:00

I want to create stacked bar plot with absolute values for variables in the

  • 0

I want to create stacked bar plot with absolute values for variables in the axis but add the percentages on each bar. This is what my data looks like:

BAM  Mapping    Reads   fraction
bam1   Mapped 22493091 0.88940452
bam1 Unmapped  2796966 0.11059548
bam2   Mapped 27018375 0.88256156
bam3 Unmapped  3595212 0.11743844
bam3   Mapped 27238774 0.89441821
bam4 Unmapped  3215407 0.10558179
bam4   Mapped 19791746 0.82984107
bam4 Unmapped  4058298 0.17015893
bam5   Mapped 23298155 0.83144569
bam5 Unmapped  4723104 0.16855431
bam6   Mapped 22563538 0.83990722
bam6 Unmapped  4300784 0.16009278
bam7   Mapped 23940480 0.88134856
bam7 Unmapped  3222984 0.11865144

I am nearly there (nevermind the x-labels – I’m using long names here):

gp <- ggplot(data=to_graph, aes(x=BAM, y=Reads, fill=Mapping, label=paste(round(fraction*100),"%", sep=""), size = 3,vjust=0, position = "stack")) +
     geom_bar(stat="identity") + 
    geom_text(position="stack")

enter image description here

But there a little niggling square on top of the legend that I want to get rid of. How to do that importantly why does it appear in the 1st place?

Cheers.

  • 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-06-13T17:42:56+00:00Added an answer on June 13, 2026 at 5:42 pm

    That spurious legend appears because you’re putting all sort of stuff inside aes that don’t need to be there. Try this:

    ggplot(data=to_graph, aes(x=BAM, y=Reads, fill=Mapping)) +
         geom_bar(stat="identity",position = "stack") + 
        geom_text(aes(label=paste(round(fraction*100),"%", sep="")),size = 3,vjust=0,position="stack")
    

    In general, things go inside aes when you mapping an aesthetic to a variable in your data. If you’re just setting it (i.e. size = 3) that goes outside of aes. Anything you put inside of aes will in general cause ggplot to attempt to create a legend for that aesthetic.

    I don’t think I’ve ever seen position mapped inside aes.

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

Sidebar

Related Questions

I want to create a vertical bar plot. This is my code: bar (x,
I am using qplot to create a stacked bar plot and would like to
I want to create a stacked bar graph as in url below (source: jpowered.com
i want create a custom json data from the mssql 2008 results so that
i want create Dynamic Slideshow in Jquery i'm Write this code var ctx =
I want to create a Silverlight app to extract and manipulate data from an
I am trying to create a Stacked Bar Chart. My requirement is I need
I need to set a unique color to each bar in the stacked bar
I want create a pdf using iText. The method which does this is a
I've tried a number of things but I can't get my plot to create

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.