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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:11:30+00:00 2026-06-08T08:11:30+00:00

I have noticed that the default for filling the bars in a histogram created

  • 0

I have noticed that the default for filling the bars in a histogram created using plot is the reverse alphabetical, while the legend in ordered alphabetically. I there any way to get both to order alphabetically? Problem is apparent in example plot below. Bonus question: how I change the left to right bar order from alphabetical to decreasing count total? Thanks

df <- data.frame(
  Site=c("A05","R17","R01","A05","R17","R01"),
  Group=c("Fungia","Fungia","Acro","Acro","Porites","Porites"),
  Count=c(6,8,6,7,2,9),
  Total=c(13,10,15,13,10,15)
)

  Site   Group Count Total
1  A05  Fungia     6    13
2  R17  Fungia     8    10
3  R01    Acro     6    15
4  A05    Acro     7    13
5  R17 Porites     2    10
6  R01 Porites     9    15

qplot(df$Site,data=df,weight=df$Count,geom="histogram", fill=df$Group, ylim = c(0,16)) + 
  xlab("Sites") + 
  ylab("Counts") + 
  scale_fill_hue(h=c(0,360), l=70, c=70,name = "Emergent Groups")

enter image description here

I am trying to order the counts from high to low and the fill colours so that they match the alphabetic ordering of the legend. I have been trying to adjust it for a few hours with the tips from the initial posts but without sucess. Any help on this would be most appreciated!!!

  • 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-08T08:11:31+00:00Added an answer on June 8, 2026 at 8:11 am

    If you just want the color order match, you can just reverse the legend: the color orders will match, but the legend will be in reverse alphabetical order:

    qplot(df$Site,data=df,weight=df$Count,geom="histogram", fill=df$Group, ylim = c(0,16)) + 
      xlab("Sites") + 
      ylab("Counts") + 
      scale_fill_hue(h=c(0,360), l=70, c=70,name = "Emergent Groups") +
      guides(fill = guide_legend(reverse = TRUE))
    

    enter image description here

    To get the alphabetical order back, precede the above code by a reordering of the Group factor:

    # reorder the groups
    df$Group <- factor(df$Group , 
                       levels=levels(df$Group)[order(levels(df$Group), decreasing = TRUE)])
    
    qplot(df$Site,data=df,weight=df$Count,geom="histogram", fill=df$Group, ylim = c(0,16)) + 
      xlab("Sites") + 
      ylab("Counts") + 
      scale_fill_hue(h=c(0,360), l=70, c=70,name = "Emergent Groups") +
      guides(fill = guide_legend(reverse = TRUE))
    

    enter image description here

    For the bonus (ordering the bars by decreasing total count), reorder the factor order of the Site variable:

    # reorder the sites
    df$Site <- factor(df$Site, 
                      levels = levels(df$Site)[order(aggregate(Count ~ Site, data = df, sum)$Count, 
                                                     decreasing = TRUE)])
    # reorder the groups
    df$Group <- factor(df$Group , 
                       levels=levels(df$Group)[order(levels(df$Group), decreasing = TRUE)])
    
    qplot(df$Site,data=df,weight=df$Count,geom="histogram", fill=df$Group, ylim = c(0,16)) + 
      xlab("Sites") + 
      ylab("Counts") + 
      scale_fill_hue(h=c(0,360), l=70, c=70,name = "Emergent Groups") +
      guides(fill = guide_legend(reverse = TRUE))
    

    enter image description here

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

Sidebar

Related Questions

I have noticed that while using the Substance UI for Java that when I
I have noticed that in the CoreDataBooks example a default database is copied to
I've noticed that when using $.post() in jquery that the default contentType is application/x-www-form-urlencoded
I have noticed that the default theme for ICS 4.0.3 in Eclipse is Theme.Holo
After setting up a replication on my server (SQL2005) I have noticed that default
I've just stared using JQuery and SoundManger2, and I have noticed that SoundManager has
I have just noticed that, by default, http://host/yourplonesite/folder/folder_contents will always reveal the contents of
We have noticed that component publishing takes a long time. The component we are
I have noticed that if you add a unobtrusive link in a refreshable partial
I have noticed that deleted branches in svn is not preserved in git. I

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.