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

The Archive Base Latest Questions

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

I started making a reproducible example to ask another question and can’t even get

  • 0

I started making a reproducible example to ask another question and can’t even get past that. Anyway I am attempting to plot categorical data into a faceted bar plot. So I made my own data set using CO3 (code at bottom). Just plotting x by itself seems normal:
enter image description here

but then gets funky when I try to facet. Showing everything is all equal.
enter image description here

That doesn’t make sense as it would indicate every sub group had equal proportions of the out come that isn’t evidenced by an ftable of the data:

                   Type Quebec Mississippi
outcome Treatment                         
none    nonchilled           7           6
        chilled              4           7
some    nonchilled           6           4
        chilled              5           5
lots    nonchilled           5           4
        chilled              6           3
tons    nonchilled           3           7
        chilled              6           6

What am I doing wrong?

library(ggplot2)
set.seed(10)
CO3 <- data.frame(CO2[, 2:3], outcome=factor(sample(c('none', 'some', 'lots', 'tons'), 
           nrow(CO2), rep=T), levels=c('none', 'some', 'lots', 'tons')))
CO3
x <- ggplot(CO3, aes(x=outcome)) + geom_bar(aes(x=outcome))
x
x  + facet_grid(Treatment~., margins=TRUE)

with(CO3, ftable(outcome, Treatment, Type))

EDIT: This problem Brian describes is an easy one to find yourself in when you need to stack data. To over come this until the next version of ggplot (I assume Hadley is aware of this problem) I have created a silly little convenience function to add an ID column to a data frame quickly:

IDer <- function(dataframe, id.name="id"){
    DF <- data.frame(c=1:nrow(dataframe), dataframe)
    colnames(DF)[1] <- id.name
    return(DF)
}

IDer(mtcars)
  • 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-31T15:26:16+00:00Added an answer on May 31, 2026 at 3:26 pm

    There is a bug in the 0.9.0 release of ggplot2 regarding facet_grid() and duplicated rows. See https://github.com/hadley/ggplot2/issues/443

    A workaround is to add a dummy column to break the duplication.

    CO3$dummy <- 1:nrow(CO3)
    
    ggplot(CO3, aes(x=outcome)) + 
      geom_bar(aes(x=outcome)) + 
      facet_grid(Treatment~., margins=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

Back in 2003 I started making web applications that used databases in PHP. Of
I started making a game, I have a global class that reads in a
I'm making a simple 2 player game in XNA and started looking into saving
I've been making small scale projects for a while now. I haven't started a
Started with this question: OpenID. How do you logout OK. So OpenID does not
Just started getting a bunch of errors on our C# .Net app that seemed
I started making a 3d game. then I stopped for a some time and
I started making this simple google chrome extension in javascript. And in the beginning
I made a mistake, and started making commits to the last tag, which lands
Weirdly, I've never come across this issue before, but I've just started making a

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.