1

I want to plot two rectangles with internal gradients beside each other using ggpattern::geom_rect_pattern(pattern = "gradient") without a border around each rectangle.

Example:

library(tidyverse)
library(ggpattern)

tibble(
  id = c("a", "b"),
  xmin = c(-1, -1),
  xmax = c(1, 1),
  ymin = c(-1, 0),
  ymax = c(0, 1)
) |> 
  ggplot() +
  geom_rect_pattern(
    aes(xmin = xmin, xmax = xmax, ymin = ymin, ymax = ymax, pattern_fill2 = id), 
    pattern_fill = "white", pattern = "gradient", pattern_orientation = "horizontal"
    ) +
  theme_classic() +
  coord_fixed(xlim = c(-1.1,1.1), ylim = c(-1.1,1.1), ratio = 1)


Which produces:

image of the problem

My issue is how do I remove the border around the rectangles?

Setting colour = "white" in geom_rect_pattern() will work to remove the outer border, but will introduce an internal border which is undesirable for my figure:

image with colour = "white"

Setting colour = NA and/or pattern_colour = NA produces the same plot as the first

the first.

Is there an aesthetic I am missing here?

Allan Cameron
  • 147,086
  • 7
  • 49
  • 87

1 Answers1

1

There seems to be a gray-filled rectGrob under the gradient fill on the finished plot, and you can just see the edges of it. If you set fill = NA this disappears.

library(tidyverse)
library(ggpattern)

tibble(
  id = c("a", "b"),
  xmin = c(-1, -1),
  xmax = c(1, 1),
  ymin = c(-1, 0),
  ymax = c(0, 1)
) |> 
  ggplot() +
  geom_rect_pattern(
    aes(xmin = xmin, xmax = xmax, ymin = ymin, ymax = ymax, pattern_fill2 = id),
    pattern_fill = "white", pattern = "gradient", fill = NA,
    pattern_orientation = "horizontal",
  ) +
  theme_classic() +
  coord_fixed(xlim = c(-1.1,1.1), ylim = c(-1.1,1.1), ratio = 1)

enter image description here

Allan Cameron
  • 147,086
  • 7
  • 49
  • 87