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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:40:12+00:00 2026-06-04T09:40:12+00:00

I really like how my dotplot looks with facet_wrap (facet labels on top) but

  • 0

I really like how my dotplot looks with facet_wrap (facet labels on top) but I’d ideally like to be able to pass it a space = “free_x” so the facets are sized appropriately. The problem with facet_grid is that the facet labels move to the side of the plot, which in this case doesn’t work well because I want each panel to be separated.

Code follows:

# load data
plotdat <- structure(list(level = c("Lost (N =328)", "Won (N =75)", "Lost (N =10)", 
                        "Won (N =65)", "Challenger (N =318)", "Incumbent (N =85)", "Arab (N =7)", 
                        "Black (N =222)", "East Asian (N =40)", "Latino (N =107)", "Other (N =10)", 
                        "South Asian (N =17)", "Not (N =252)", "Statewide (N =151)"), 
                mean = c(0.59834264517378, 0.645308353066667, 0.6382179387, 
                        0.646399186046154, 0.595756747751572, 0.649457274258823, 
                        0.682776774142857, 0.557334915725225, 0.6654738063, 0.68260777364486, 
                        0.6061308922, 0.613378378411765, 0.616298597519841, 0.591703758423841
                ), se = c(0.00597842210656315, 0.0113080614816089, 0.044927778673023, 
                        0.011274258338002, 0.00622316181664198, 0.00900474213888581, 
                        0.0247451786416615, 0.00690804451732034, 0.0116899960061005, 
                        0.00777478853477299, 0.0183766282892234, 0.0166464474073244, 
                        0.00669527297092827, 0.00887170639612841), N = c(328L, 75L, 
                        10L, 65L, 318L, 85L, 7L, 222L, 40L, 107L, 10L, 17L, 252L, 
                        151L), var = structure(c(1L, 1L, 2L, 2L, 3L, 3L, 4L, 4L, 
                                4L, 4L, 4L, 4L, 5L, 5L), .Label = c("Primary Election", "General Election", 
                                "Incumbency", "Race", "Statewide District"), class = "factor")), .Names = c("level", 
                "mean", "se", "N", "var"), row.names = c(NA, 14L), class = "data.frame")
library('ggplot2')

# with facet_wrap:
ggplot(plotdat, aes(x = mean, xmin = mean-se, xmax = mean+se, y = level)) + 
    geom_point() + geom_segment( aes(x = mean-se, xend = mean+se, 
                    y = level, yend=level)) +
    facet_wrap(~var, ncol=1, scales = "free_y") +
    theme_bw() + opts(axis.title.x = theme_text(size = 12, vjust = .25))+ 
    xlab("Mean V (Brightness) for Candidate's Face") + ylab("") +
    opts(title = expression("Skin Complexion for 2010 Minority Candidates"))

# with facet_grid:
ggplot(plotdat, aes(x = mean, xmin = mean-se, xmax = mean+se, y = level)) + 
    geom_point() + geom_segment( aes(x = mean-se, xend = mean+se, 
                    y = level, yend=level)) +
    facet_grid(var~., scales = "free_y", space = "free_y") +
    theme_bw() + opts(axis.title.x = theme_text(size = 12, vjust = .25))+ 
    xlab("Mean V (Brightness) for Candidate's Face") + ylab("") +
    opts(title = expression("Skin Complexion for 2010 Minority Candidates"))

Any suggestions? Thanks very much!

  • 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-04T09:40:13+00:00Added an answer on June 4, 2026 at 9:40 am

    Update Using the ggplot grob, this is fairly easy to do. See here or here

    ggplot grob version

    library(ggplot2)
    library(dplyr)
    library(grid)
    
    # Get the plot; plotdat data frame is below
    p = ggplot(plotdat, aes(x = mean, xmin = mean-se, xmax = mean+se, y = level)) + 
        geom_point() + geom_segment( aes(x = mean-se, xend = mean+se, 
                        y = level, yend=level)) +
        facet_wrap(~var, ncol=1, scales = "free_y") +
        theme_bw() + theme(axis.title.x = element_text(size = 12, vjust = .25))+ 
        xlab("Mean V (Brightness) for Candidate's Face") + ylab("") +
        ggtitle("Skin Complexion for 2010 Minority Candidates")
    
    
    # From 'plotdat', get the number of 'levels' for each 'var'.
    # That is, the number y-breaks in each panel.
    N <- plotdat %>% group_by(var) %>% 
       summarise(count = n()) %>% 
       `[[`(2)
    
    # Get the ggplot grob
    gt = ggplotGrob(p) 
    
    # Get the locations of the panels in the gtable layout.
    panels <- gt$layout$t[grepl("panel", gt$layout$name)]
    
    # Replace the default panel heights with relative heights
    gt$heights[panels] <- unit(N, "null")
    
    ## Draw gt
    grid.newpage()
    grid.draw(gt)
    

    enter image description here

    Original answer
    EDIT: Updated to ggplot2 version 0.9.3.1

    This is not going to answer your question. It tweaks the facet_grid look.

    I’m not sure what you mean by “each panel being separated”. If you are concerned that the strip text in the facet_grid plot extends beyond the boundaries of the strip, the text can be rotated using theme(strip.text.y = element_text(angle = 0)). Furthermore, the text can be made to wrap round to multiple lines using str_wrap from the stingr package.

    # load data
    plotdat <- structure(list(level = c("Lost (N =328)", "Won (N =75)", "Lost (N =10)", 
                            "Won (N =65)", "Challenger (N =318)", "Incumbent (N =85)", "Arab (N =7)", 
                            "Black (N =222)", "East Asian (N =40)", "Latino (N =107)", "Other (N =10)", 
                            "South Asian (N =17)", "Not (N =252)", "Statewide (N =151)"), 
                    mean = c(0.59834264517378, 0.645308353066667, 0.6382179387, 
                            0.646399186046154, 0.595756747751572, 0.649457274258823, 
                            0.682776774142857, 0.557334915725225, 0.6654738063, 0.68260777364486, 
                            0.6061308922, 0.613378378411765, 0.616298597519841, 0.591703758423841
                    ), se = c(0.00597842210656315, 0.0113080614816089, 0.044927778673023, 
                            0.011274258338002, 0.00622316181664198, 0.00900474213888581, 
                            0.0247451786416615, 0.00690804451732034, 0.0116899960061005, 
                            0.00777478853477299, 0.0183766282892234, 0.0166464474073244, 
                            0.00669527297092827, 0.00887170639612841), N = c(328L, 75L, 
                            10L, 65L, 318L, 85L, 7L, 222L, 40L, 107L, 10L, 17L, 252L, 
                            151L), var = structure(c(1L, 1L, 2L, 2L, 3L, 3L, 4L, 4L, 
                                    4L, 4L, 4L, 4L, 5L, 5L), .Label = c("Primary Election", "General Election", 
                                    "Incumbency", "Race", "Statewide District"), class = "factor")), .Names = c("level", 
                    "mean", "se", "N", "var"), row.names = c(NA, 14L), class = "data.frame")
    library('ggplot2')
    library(stringr)
    
    plotdat$var = str_wrap(plotdat$var, width = 10)
    
    # with facet_grid:
    ggplot(plotdat, aes(x = mean, xmin = mean-se, xmax = mean+se, y = level)) + 
        geom_point() + geom_segment( aes(x = mean-se, xend = mean+se, 
                        y = level, yend=level)) +
        facet_grid(var~., scales = "free_y", space = "free_y") +
        theme_bw() + 
        ggtitle("Skin Complexion for 2010 Minority Candidates") +
        xlab("Mean V (Brightness) for Candidate's Face") + ylab("") +
        theme(axis.title.x = element_text(size = 12, vjust = .25), 
              strip.text.y = element_text(angle = 0))
    

    If “panels to be separated” means “additional space between the panels”, use theme(panel.margin = unit(2, "line"), after loading grid.

    library(grid)
    ggplot(plotdat, aes(x = mean, xmin = mean-se, xmax = mean+se, y = level)) + 
        geom_point() + geom_segment( aes(x = mean-se, xend = mean+se, 
                        y = level, yend=level)) +
        facet_grid(var~., scales = "free_y", space = "free_y") +
        theme_bw() + 
        ggtitle("Skin Complexion for 2010 Minority Candidates") +
        xlab("Mean V (Brightness) for Candidate's Face") + ylab("") +
        theme(axis.title.x = element_text(size = 12, vjust = .25), 
              strip.text.y = element_text(angle = 0),
              panel.margin = unit(2, "lines"))
    

    enter image description here

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

Sidebar

Related Questions

I really like Noty plugin but i can`t understand how could i pass some
I really like how Consolas looks with ClearType enabled but unfortunately it makes everything
I really like the magento structure but finding things is very hard ;) My
I really like the promote to home page feature of drupal. But what if
I really like the idea of automatic binding generation like SWIG does. But it
I really like being able to use =~ and !~ in Perl to evaluate
I really like the strtotime() function, but the user manual doesn't give a complete
I really like py.test , but I am having lots of difficulty understanding how
I really like this approach for handling sqlite database when developing for Android but
I really like Template Toolkit and like how it works with Catalyst , but

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.