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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:03:52+00:00 2026-05-31T17:03:52+00:00

This question has been asked before but the answers aren’t always clear or are

  • 0

This question has been asked before but the answers aren’t always clear or are complicated. I’m hoping that newer versions of ggplot2 have lead to easier solutions.

How can you eliminate just the vertical lines of a ggplot without eliminating the axis tick marks or labels? This would really be nice for bar graphs as it would eliminate some unnecessary distraction from the graphic.

Here is some sample code to aid the discussion:

library(ggplot2)
set.seed(10)
CO3 <- data.frame(id=1:nrow(CO2), 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))+ 
     facet_grid(Treatment~Type, margins='Treatment', scales='free') 
x +  theme_bw() + opts(axis.text.x=theme_text(angle= 45, vjust=1, hjust= 1))
  • 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-31T17:03:53+00:00Added an answer on May 31, 2026 at 5:03 pm

    Try this, redifining guide_grid.

    This solution is from the Cookbook for R

    # Save the original definition of the guide_grid
    guide_grid_orig <- ggplot2:::guide_grid
    
    # Create the replacement function
    guide_grid_no_vline <- function(theme, x.minor, x.major, y.minor, y.major) {  
      x.minor <- setdiff(x.minor, x.major)
      y.minor <- setdiff(y.minor, y.major)
    
      ggname("grill", grobTree(
        theme_render(theme, "panel.background"),
        if(length(y.minor) > 0) theme_render(
          theme, "panel.grid.minor", name = "y",
          x = rep(0:1, length(y.minor)), y = rep(y.minor, each=2), 
          id.lengths = rep(2, length(y.minor))
          ),
        if(length(y.major) > 0) theme_render(
          theme, "panel.grid.major", name = "y",
          x = rep(0:1, length(y.major)), y = rep(y.major, each=2), 
          id.lengths = rep(2, length(y.major))
          )
        ))
    }
    # Set the environment to be the same as original
    environment(guide_grid_no_vline) <- environment(ggplot2:::guide_grid)
    
    # Assign the function inside ggplot2
    assignInNamespace("guide_grid", guide_grid_no_vline, ns="ggplot2")
    
    # Draw the plot with the redefined guide_grid
    ggplot(CO3, aes(x=outcome)) + 
      geom_bar(aes(x=outcome))+ 
      facet_grid(Treatment~Type, margins='Treatment', scales='free')  +
      theme_bw() + 
      opts(axis.text.x=theme_text(angle= 45, vjust=1, hjust= 1))
    
    # Restore the original guide_grid function so that it will draw all gridlines again
    assignInNamespace("guide_grid", guide_grid_orig, ns="ggplot2")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question has been asked before, but I can't find any answers that have
I know this question has been asked before, but many answers don't give clear
This has been asked before (question no. 308581) , but that particular question and
This question has been asked before and there have been windows-specific answers but no
I know this question has been asked before, but none of the previous answers
I know this question has been asked before, but none of the answers in
This question has been asked here before, but the author wasn't very clear and
I realize that this question has been asked before - but none of the
This question has been asked in different ways before, but the answers don't help
Hey a similar question has been asked before, but none that answers mine exactly.

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.