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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:50:15+00:00 2026-06-12T09:50:15+00:00

Possible Duplicate: how to define fill colours in ggplot histogram? I want to plot

  • 0

Possible Duplicate:
how to define fill colours in ggplot histogram?

I want to plot (histogram) counts of fishes per length class from a data frame which summarize this information in a binned format (data.frame(…,length=length, counts=N)). I’m a new user of ggplot2, but seems It could be a good choice. Can I create this histogram from a data.frame object?

Sorry for being so brief, Here is the structure of a piece of df,

'data.frame':   416 obs. of  3 variables:
 $ specie: Factor w/ 1 level "speciesA": 1 1 1 1 1 1 1 1 1 1 ...
 $ length: num  34.5 35 35.5 36 36.5 37 37.5 38 38.5 39 ...
 $ Counts: num  2 0 0 0 1 0 1 1 0 1 ...

In this case, fishers catch 2 individuals 34.5 cm large, 1 36.5, and so on…
Thank you very much for your answers

  • 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-12T09:50:16+00:00Added an answer on June 12, 2026 at 9:50 am

    Since you did not provide a sample of your data, I have created data per your description.

    Length of fishes from 34.5 to 49.5 (arbitrary units: a.u.). Min length of fishes was 34.5 and Max length of fishes was 49.5

     x <- 34.5:49.5
    

    Number of fishes having a specific length starts at 0 and ends at 2.

     y <- 0:2
    

    Create a sample of counts having the length of x

     Counts <- sample(y, length(x), replace=TRUE)
    

    Create a dataframe1 that includes length and counts. Notice: The structure of df1 satisfies the data structure per your description

    df1 <- data.frame(length=x, Counts = Counts)
    

    Since you already counted the number of fishes having a specific length, you have to convert it back to the original format, i.e., if 2 fishes having 34.5(a.u), it should be converted back to two 34.5s.

    df2 <- data.frame(length = rep(df1$length, df1$Counts))
    

    Plot the data using ggplot function. Notice there are many ways to do the same plot. You may try geom_histogram to get the same plot as well.

    require("ggplot2")
    ggplot(data=df2, aes(x=length, xmin=34.5, xmax=49.5)) + stat_bin(binwidth=1)
    

    Check this site for more info

    Hope this helps!

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

Sidebar

Related Questions

Possible Duplicate: ImproperlyConfigured: Middleware module “django.middleware.csrf” does not define a “CsrfResponseMiddleware” class I am
Possible Duplicate: Best way to define private methods for a class in Objective-C Hi,
Possible Duplicate: Conditional “Browsable” Attribute I define AppSettings class that have a few properties.
Possible Duplicate: Subclassing Python tuple with multiple __init__ arguments I want to define a
Possible Duplicate: How do I define a template function within a template class outside
Possible Duplicate: Is it possible to define more than one function per file in
Possible Duplicate: How do I prevent a class from being allocated via the 'new'
Possible Duplicate: Define a method that has many (or infinite) arguments I have the
Possible Duplicate: Is it possible to define enumalpha? Is there any equivalent of Java
Possible Duplicate: The written versions of the logical operators. I notice that C++ define

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.