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:
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:
Setting colour = NA
and/or pattern_colour = NA
produces the same plot as the first
.
Is there an aesthetic I am missing here?
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)