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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:50:25+00:00 2026-06-05T16:50:25+00:00

The gridExtra package adds a grob of class pattern that lets one fill rectangles

  • 0

The gridExtra package adds a grob of class “pattern” that lets one fill rectangles with patterns. For example,

library(gridExtra)
grid.pattern(pattern = 1)

creates a box filled with diagonal lines. I want to create a stack of panels in which each panel is filled with these diagonal lines. This is easy:

library(lattice); library(gridExtra)
examplePlot <- xyplot(
  1 ~ 1 | 1:2, 
  panel = function () grid.pattern(pattern = 1),
  layout = c(1, 2),

  # Remove distracting visual detail
  scales = list(x=list(draw=FALSE), y=list(draw=FALSE)),
  strip = FALSE, xlab = '', ylab = ''
)
print(examplePlot)

The problem is that the diagonal lines aren’t aligned across panels. That is, there is a visual “break” where the bottom of the first panel meets the top of the second panel: at that point, the lines don’t line up. This is the problem that I want to fix.

I can eliminate most of the visual break by adding the argument pattern.offset = c(.2005, 0) to the grid.pattern call, and making sure that it applies only to the bottom panel. But this solution doesn’t generalize. For example, if I change the pattern (e.g., by using the granularity argument to grid.pattern), this solution won’t work. Is there a more general fix?

  • 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-05T16:50:27+00:00Added an answer on June 5, 2026 at 4:50 pm

    To make this work, you’ll have to take charge of setting the panel.height argument used by print.trellis. (To see why, try resizing your plotting device after running your example code: as the size of the device and the panels changes, so does the matching/mismatching of the lines):

    ## Calculate vertical distance (in mm) between 45 degree diagonal lines
    ## spaced 5mm apart (the default distance for grid.pattern).
    vdist <- 5 * sqrt(2)
    
    nLines <- 8L    ## can be any integer
    panelHeight <- list(x = nLines*vdist, units = "mm", data = NULL)
    
    ## Plot it
    print(examplePlot, panel.height=panelHeight)
    

    enter image description here

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

Sidebar

Related Questions

The grid.pattern function supplied by gridExtra will fill a polygon with diagonal lines. I
With grid.arrange I can arrange multiple ggplot figures in a grid to achieve a
This is cross-posted on the ggplot2 google group My situation is that I'm working
library(ggplot2) df <- data.frame(x=1:10, y=rnorm(10)) p1 <- ggplot(df, aes(x,y)) + geom_point() plist <- list(p1,p1,p1,p1,p1)
I have a short routine which arranges ggplot and grid graphics using the grid.arrange
There are bunch of files that are updated on a directory called: c:/files. These
as a new ggplot2 user, I am a bit lost with the amount of
update: the error only occurs when logged into R from within emacs what works:
It's time for me to write your grandmother her first Java word search program.
Some geom obscure the key to other geoms in the legend (notably, boxplot) How

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.