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.

2
  • 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: stat.ethz.ch/R-manual/R-devel/doc/html/NEWS.html.
    – teunbrand
    Jul 13, 2020 at 9:35
  • Thank you for that good news. I really appreciate your honest answer! Jul 15, 2020 at 5:25

1 Answer 1

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

1
  • Very good! This is much better than I was expecting! Thank you so much! I hope ggpattern gets incorporated into ggplot2. Jul 15, 2020 at 5:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.