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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:38:33+00:00 2026-06-14T07:38:33+00:00

Using this data: library(ggplot2) dd <- data.frame(id = c(A, A, B, B), prepost =

  • 0

Using this data:

library(ggplot2)
dd <- data.frame(id = c("A", "A", "B", "B"), prepost = c("pre", "post"), 
         value = 1:4)

this one works:

qplot(id, value, data = dd, fill = prepost, geom = "bar")

however, the next one gives the indicated error message. The only difference between the two is the addition of group = prepost to the end of the command; however, since we had already written fill = prepost that should be the default group anyways.

> qplot(id, value, data = dd, fill = prepost, geom = "bar", group = prepost)
 Error in pmin(y, 0) : object 'y' not found

We can fix up the last one by adding stat = "identity" like this:

qplot(id, value, data = dd, fill = prepost, geom = "bar", group = prepost, 
      stat = "identity")

I have two questions:

(a) Why does the qplot which gave the error message not work when the others do work?

(b) If we use a continuous y aesthetic with geom_bar then what is supposed to happen if one does not specify stat? From the first qplot it seems that in that case it acts as if stat="identity" but in the presence of group specifying stat="identity" or not reveals a difference.

(By the way, this question seems somewhat related although its different enough that it does not seem to answer this question: Issue with ggplot2, geom_bar, and position="dodge": stacked has correct y values, dodged does not)

  • 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-14T07:38:34+00:00Added an answer on June 14, 2026 at 7:38 am

    A good question!

    I will echo a earlier comment by @joran

    I generally find that people are less confused with ggplot once they learn to stop using qplot

    Your qplot call can be recreated using

    ggplot(dd) + geom_bar(aes(x = id, y = value, fill = prepost))
    

    Now, if you read the help for geom_bar it lists the aesthetics it understands, group is not one of them (so perhaps you can’t expect it to work as you wish when you do this)

    If you read the help for group you will see that it is an aesthetic that allows you to override the default interaction of all discrete variables.

    If you group by prepost alone, you are not grouping by the discrete x axis variable id, which the default would be included as well,

    Therefore

    ggplot(dd) + 
     geom_bar(aes(x=id, y = value, fill = prepost, group = interaction(id, prepost)))
    

    works, but the grouping is entirely redundant as this is the default.

    If you specify just prepost or id as your grouping, it confuses stat_bin (the underlying method that is crunching the numbers to create the values for the bar plot. Hence you need to use stat_identity instead.


    EDIT: as noted by the OP in the comments below, this is related to a known issue and will give better warnings in the next version (or th current dev version on github

    From the NEWS

    • stat_bin now produces warning messages when it is used with set or
      mapped y values. Previously, it was possible to use stat_bin and
      also set/map y values; if there was one y value per group, it would
      display the y values from the data, instead of the counts of cases for
      each group. This usage is deprecated and will be removed in a future
      version of ggplot2. (Winston Chang. Fixes #632)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have grabbed some XML data using this piece of jQuery: $.ajax({ type: POST,
Using This code: I am tring to fill the page with the data and
I am using this code to post some data $('.update_btn').live(click,function() { var ID =
Lets say we have a native library that works with data like this: double
library(ggplot2) df <- data.frame(x=1:10, y=rnorm(10)) p1 <- ggplot(df, aes(x,y)) + geom_point() plist <- list(p1,p1,p1,p1,p1)
I created a simple Dotplot() using this data: d <- data.frame(emot=rep(c(happy,angry),each=2), exp=rep(c(exp,non-exp),2), accuracy=c(0.477,0.587,0.659,0.736), Lo=c(0.4508,0.564,0.641,0.719),
I am using ggplot2 to plot simple line charts of time series data. One
i Want to fetch this data using json decode. Please Help.. So far i
I have a dict object. I dumped the data using this: for alldata in
Im using this code: protected String getContactInfo() { Cursor cursor = getContentResolver().query(ContactsContract.Data.CONTENT_URI, null, null,

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.