0

Is there a way to introduce the arguments "density" and "angle", or any other interesting ones from "ggplot::barplot" into "ggplot::geom_ribbon"?

I have been looking for basic texture of geom_ribbon -like points and crosses and lines-, instead of only "fill"-ing them with variable colors. I saw the package ggtexture, but it uses .svg external files, and does include barplotting, but not ribbons similar to geom_ribbons, apparently. The most promising was the barplots I saw here: Barplots example with texture. I mean, according to the description, geom_ribbon is close to the drawing of barplots, as if they were areas of y height.

I, however, don't understand how to modify source code myself.

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
  • 1
    This has been a difficulty to achieve in ggplot for non-rectangles because the grid system doesn't allow non-rectangular clipping paths, which would be needed for ribbons. However, if you follow the R-devel news, you can see that this will soon be possible: https://stat.ethz.ch/R-manual/R-devel/doc/html/NEWS.html. – teunbrand Jul 13 '20 at 09:35
  • Thank you for that good news. I really appreciate your honest answer! – Sebastian Schuth Hurtado Jul 15 '20 at 05:25

1 Answers1

1

You could try the (non-CRAN) package ggpattern, as demonstrated in Ian Campbell's recent question and answer

Here's a demo using a geom_ribbon_pattern:

remotes::install_github("coolbutuseless/ggpattern")
library(ggpattern)

x <- seq(pi/2, 20, 0.1)
df <- data.frame(x, lower = 10 * (cos(x)/x - .3), upper = (10 * -cos(x)/x + .3))
ggplot(df) +
  geom_ribbon_pattern(aes(x, ymin = lower, ymax = upper), fill = "gray95",
                      color = "black", 
                      pattern = "stripe",
                      pattern_fill = "gray80",
                      pattern_angle = 45,
                      pattern_density = 0.2,
                      pattern_spacing = 0.05) +
  coord_equal() +
  theme_classic()

enter image description here

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