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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:28:13+00:00 2026-05-31T02:28:13+00:00

I am trying to make a faceted ggplot sorted by two discrete variables on

  • 0

I am trying to make a faceted ggplot sorted by two discrete variables on the x axis. The problem is that I would like to have the vertically adjacent entries all touching. Currently there is space between rows based on which levels of the factor are in the top plot vs bottom. sorry this reproducible example is a bit verbose.

npats=20   

simsympt=c(id=1,date=1,tx="control",sympt=0) 

for(i in 1:npats)

 {   days=abs(round(rnorm(1,100,40),0))
     id=rep(as.character(i),days)
     date=1:days
     tx=rep(sample(c("control","treatment"),1),days)
     sympt= sample(0:10, days,p=c(12,3,3,2,1,1,1,1,1,1,1),rep=T)

   simsympt=      rbind(simsympt,      cbind(id,date,tx,sympt) )
  }
       ####tidy things up a bit   
     simsympt=data.frame(simsympt)[-1,]
     colnames(simsympt)=c('id','date','tx','level')
     simsympt$date=as.numeric(as.character(simsympt$date))
     simsympt$level=as.numeric(as.character(simsympt$level))
     #simsympt$id=as.numeric(as.character(simsympt$id))

  head(simsympt)

##now the important stuff

 p <- ggplot(simsympt, aes(x=date,y=id))    
 p=   p + geom_tile(aes(fill=level)) +   
      facet_grid(tx~.,drop=T,space="free")+
      scale_y_discrete(expand=c(0,0),drop=T)
 p

No description here

All I need is to remove the all the vertical space between rows in both the top and the bottom graph(facet). For example, since id number 15 is in the control group there should not be a row for her in the treatment group.
Thanks,
Seth

  • 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-31T02:28:14+00:00Added an answer on May 31, 2026 at 2:28 am
    library("grid")
    p + opts(panel.margin=unit(0,"pt"))
    

    EDIT: after further clarification

    Removed the wrong space. What you want is to change your facet_grid call to include a scales="free" argument.

    p <- ggplot(simsympt, aes(x=date,y=id))    
    p=   p + geom_tile(aes(fill=level)) +   
         facet_grid(tx~.,drop=T,space="free",scales="free")+
         scale_y_discrete(expand=c(0,0),drop=T)
    

    enter image description here

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

Sidebar

Related Questions

Trying to make a regex that can handle input like either: Beverly Hills, CA
Trying to make simple minesweeper game in python, but have one problem. I have
I am trying to make a faceted plot in ggplot2 of the coefficients on
Trying to make a make generic select control that I can dynamically add elements
Trying to make a custom :confirm message for a rails form that returns data
Trying to make simple jQuery function to create a scrollToTop button that fades in
trying to make one horizontal box.. inside that update limits. if u see the
Im trying to make an app that converts distance/area/volume using spinners as a unit
I am trying to make a kind of 'faceted search' in ASP.NET and am
Right now I'm trying make some browser based game. But I have little questions.

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.