trevorld / ggpattern

ggplot geoms with pattern fills
https://trevorldavis.com/R/ggpattern/dev/
Other
361 stars 18 forks source link

change spacing without changing size #21

Closed kklot closed 3 years ago

kklot commented 3 years ago

I mapped a variable to spacing, so using pattern_spacing within aes works. But it also changes the size of the circle (I'm using pattern="circle") which conveys different meanings as it is another dimension. I kept a fixed pattern_density=0.05.

How can I change the spacing without changing the size of the pattern?

coolbutuseless commented 3 years ago

Hi @kklot

You will have to manually set sizes with scale_pattern_size* functions.

library(ggplot2)
library(ggpattern)
#> 
#> Attaching package: 'ggpattern'
#> The following objects are masked from 'package:ggplot2':
#> 
#>     flip_data, flipped_names, gg_dep, has_flipped_aes, remove_missing,
#>     should_stop, waiver

df <- data.frame(trt = c("a", "b", "c"), outcome = c(2.3, 1.9, 3.2))

ggplot(df, aes(trt, outcome)) +
  geom_col_pattern(aes(fill=trt, pattern_spacing = trt, pattern_density = trt),colour='black', pattern = 'circle') +
  theme_bw() +
  labs(title = "ggpattern + coord_fixed()") +
  coord_fixed(ratio = 1/2) +
  scale_pattern_spacing_manual(values = c(a = 0.05, b = 0.1, c = 0.2)) +
  scale_pattern_density_manual(values = c(a = 0.1, b = 0.05, c = 0.025)) 

Created on 2020-12-19 by the reprex package (v0.3.0)