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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:08:28+00:00 2026-06-11T22:08:28+00:00

Despite using ggplot a few times already, I am really struggling to make any

  • 0

Despite using ggplot a few times already, I am really struggling to make any headway with this problem. I guess it will be easiest to explain what I want to do without my abominable attempt at using ggplot, The following is quite ugly too, but it’s the best I can manage at the moment 🙁

require(mice)
impute <- mice(nhanes, seed = 101)

counts <- table(nhanes$hyp)
barplot(counts, main="hyp", xlab="observed")

x11()
counts <- table(complete(impute,1)$hyp)
barplot(counts, main="hyp", xlab="Imputation 1")

x11()
counts <- table(complete(impute,2)$hyp)
barplot(counts, main="hyp", xlab="Imputation 2")

x11()
counts <- table(complete(impute,3)$hyp)
barplot(counts, main="hyp", xlab="Imputation 3")

x11()
counts <- table(complete(impute,4)$hyp)
barplot(counts, main="hyp", xlab="Imputation 4")

x11()
counts <- table(complete(impute,5)$hyp)
barplot(counts, main="hyp", xlab="Imputation 5")

I would like to create a nice looking grid of plots showing these kind of barplots in ggplot – for example, 1 row of 6, all with the same scale on the y axis so that they can be easily compared.

I think I should use ldt <-complete(impute,"long", include=TRUE) and then melt(ldt, c(".imp",".id","hyp")) but I just can’t work out how to call ggplot after that 🙁

Please note that I have many different variables in my real data, and this only applies to the categorical variables. I was thinking I could make make a function and then run that using sapply, but only on the categorical columns ? But I don’t have much idea of how to do that !

  • 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-11T22:08:29+00:00Added an answer on June 11, 2026 at 10:08 pm

    A couple of points

    1. You need to have hyp or the variable in question as a factor. It is easiest to remove
      the NA values before you do this.
    2. facet_wrap (one variable) or facet_grid (one or more variables) will arrange the plots nicely for you.

    For example

    ldt <-complete(impute,"long", include=TRUE)
    
    ggplot(ldt[!is.na(ldt$hyp),], aes(x= factor(hyp))) + 
      geom_bar() + 
      facet_wrap(~.imp, nrow = 1) +
      xlab('Observed') +
      scale_y_continuous(expand = c(0,0))
    

    enter image description here

    in long form

    Now you want facet_grid with scales = 'free_y'

    all_long <- melt(ldt, c(".imp",".id","hyp"))
    ggplot(all_long[!is.na(all_long$hyp),], aes(x= factor(hyp))) + 
      geom_bar() + 
      facet_grid(variable ~.imp, scales = 'free_y') +
      xlab('Observed') +
      scale_y_continuous(expand = c(0,0))
    

    enter image description here

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

Sidebar

Related Questions

Despite using PHP for years, I've never really learnt how to use expressions to
This is a problem i wasn't able to solve despite extensive searches on the
Despite I have been using MVC in PHP many times, I found out that
I'm getting a ConcurrentModificationException despite using the iterator to perform the remove operation. Any
I have a piece of code here that does not work despite me using
I'm using xval to use client side validation in my asp.net mvc2 web-application. Despite
Despite working on EE for about 3 weeks now, believe it or not, this
Basically I'm using Flash to connect to a Java server. Despite my Java application
Im using ASPxPopUpControll in which I have ASPxCallBack panel. THis CallbackPanel was embeded there
I'm getting cin cout and endl as undeclared errors despite using #include <iostream> #include

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.