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 7920299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:09:41+00:00 2026-06-03T16:09:41+00:00

A minor question about plotting stacked barplot in R. The stacked bars represent the

  • 0

A minor question about plotting stacked barplot in R.
The stacked bars represent the series bottom-to-top.
But the legend always shows the series top-to-bottom. I think that is also true with ggplot2::geom_bar

Is there any nicer idiom than using rev(...) twice inside either legend() or barplot() as in:

exports <- data.frame(100*rbind('Americas'=runif(6),'Asia'=runif(6),'Other'=runif(6)))
colnames(exports) <- 2004:2009
series_we_want <- c(1,2,3)
barplot( as.matrix(exports[series_we_want,]), col=mycolors, ...)
legend(x="topleft", legend=rev(rownames(exports)[series_we_want]), col=rev(mycolors) ...)

(If you omit one of the rev()'s the output is obviously meaningless. Seems like an enhance case for adding a single flag yflip=TRUE or yreverse=TRUE)

  • 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-03T16:09:45+00:00Added an answer on June 3, 2026 at 4:09 pm

    This is what I got using your code:

    exports <- data.frame(100*rbind('Americas'=runif(6),'Asia'=runif(6),'Other'=runif(6)))
    colnames(exports) <- 2004:2009
    series_we_want <- c(1,2,3)
    barplot( as.matrix(exports[series_we_want,]))
    legend(x="topleft", legend=rev(rownames(exports)[series_we_want]))
    

    enter image description here

    try this:

    exports <- data.frame(100*rbind('Americas'=runif(6),'Asia'=runif(6),'Other'=runif(6)))
    colnames(exports) <- 2004:2009
    series_we_want <- c(1,2,3)
    test_data<-as.matrix(exports[series_we_want])
    
     barplot( test_data, 
              legend.text=as.character(rev(rownames(exports)[series_we_want])), 
               args.legend = list(x="topleft"))
    

    seems to produce the legend in the opposite order of what you have

    enter image description here

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

Sidebar

Related Questions

a minor question but it's driving me nuts. I'm programatically generating about 50 DDLs
Hii, there are many others had already post so many question about this..But here
** MAJOR UPDATE ** I made a minor mistake but I'm still curious about
This is probably a silly question, but I'm following a videocast about Rails, right
Ive found simlar posts before about this but nothing really answers the question. In
I have a working NSCollectionView with one minor, but critical, exception. Getting and highlighting
I know it's a minor annoyance.. but it's still an annoyance and it baffles
I know that there are no fixed rules about software version control but I
I know that almost everything is already said about CMSs, but what interests me
This is a minor question, more of a curiosity. When creating MetaData class for

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.