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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:02:08+00:00 2026-05-15T15:02:08+00:00

I fit a count model to a vector of actual data and would now

  • 0

I fit a count model to a vector of actual data and would now like to plot the actual and the predicted as a grouped (dodged) bar chart. Since this is a count model, the data are discrete (X=x from 0 to 317). Since I am fitting a model, I only have already-tabulated data for the predicted values.

Here is how my original data frame looks:

  actual predicted
1   3236 3570.4995
2   1968 1137.1202
3    707  641.8186
4    302  414.8763
5    185  285.1854
6    104  203.0502

I transformed the data to be plotted with ggplot2:

melted.data <- melt(plot.data)
melted.data$realization <- c(rep(0:317, times=2))
colnames(melted.data)=c('origin','count','realization')

So that my data frame now looks like this:

head(melted.data)
  origin count realization
1 actual  3236           0
2 actual  1968           1
3 actual   707           2
4 actual   302           3
5 actual   185           4
6 actual   104           5
> tail(melted.data)
       origin        count realization
631 predicted 1.564673e-27         312
632 predicted 1.265509e-27         313
633 predicted 1.023552e-27         314
634 predicted 8.278601e-28         315
635 predicted 6.695866e-28         316
636 predicted 5.415757e-28         317

When I try to graph it (again, I’d like to have the actual and predicted count –which is already tabulated in the data– by discrete realization), I give this command:

ggplot(melted.data, stat="identity", aes(x=realization, fill=origin)) + geom_bar(position="dodge")

Yet it seems like the stat parameter is not liked by ggplot2, as I don’t get the correct bar height (which would be those of the variable “count”).

Any ideas?

Thanks,

Roberto.

  • 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-15T15:02:08+00:00Added an answer on May 15, 2026 at 3:02 pm

    You need y-values in the aes mapping if you use stat_identity (column count). Try the following:

    ggplot(melted.data, aes(x=realization, y=count, fill=origin)) + 
           stat_identity(position="dodge", geom="bar")
    

    or

    ggplot(melted.data, aes(x=realization, y=count, fill=origin)) + 
           geom_bar(position="dodge", stat="identity")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have fit my discrete count data using a variety of functions for comparison.
I would like to take my User model and break it down by day,
I have a vector of count data that is strongly over dispersed and zero
I would like to count the number of tags given a specific article. I've
I would like to make an interaction plot to visually display the difference or
I have a wide flash movie (to fit in more screen resolution). I would
What is the best practice of introducing custom (typically volatile) data into entity model
I have a model that looks like this: class Category(models.Model): name = models.CharField(max_length=60) class
So I'm trying to look at an input, and count words that fit a
I'll try and describe best I can. Working with a bad data model. Table1

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.