trevorld / ggpattern

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

[BUG] pattern_spacing and pattern_density doesn't work with magick package #96

Closed KristinaGagalova closed 1 year ago

KristinaGagalova commented 1 year ago

Hi,

I am using ggpattern with the maverick package and am not getting the expected output. I would like the pattern of my image to be bigger and have more spacing.

This is my code

ggplot(metMelt, aes(fill=Flavonoids,y=value, x=variable)) + 
  geom_bar_pattern(position="stack",stat="identity",
  aes(
      pattern_type = Flavonoids
    ),
        pattern = 'magick',
        pattern_fill         = 'white',
        pattern_spacing = 1,
        pattern_density = 0.8, 
        fill                 = 'black',
        colour               = 'black',
      ) +
  scale_pattern_type_discrete(choices = c("gray0","gray15","horizontal2","vertical2" )) +
  theme_bw() +
  xlab("") +
  ylab(expression(mu*"g/g fresh weight")) +
  theme(axis.text = element_text(size=20,colour = "black"),
        axis.title = element_text(size=22),legend.position="right",
        legend.text = element_text(size=13),
        legend.title = element_blank(),
        legend.key.size = unit(1.5, 'cm'))

The pattern_spacing and pattern_density options don't do anything, is this expected? Session info

R version 4.2.2 (2022-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 22000), RStudio 2022.7.2.576

Locale:
  LC_COLLATE=English_Canada.utf8  LC_CTYPE=English_Canada.utf8   
  LC_MONETARY=English_Canada.utf8 LC_NUMERIC=C                   
  LC_TIME=English_Canada.utf8    

Package version:
  cachem_1.0.6       class_7.3.20       classInt_0.4.8    
  cli_3.4.1          colorspace_2.0.3   DBI_1.1.3         
  e1071_1.7.13       fansi_1.0.3        farver_2.1.1      
  fastmap_1.1.0      ggpattern_1.1.0-0  ggplot2_3.4.0     
  glue_1.6.2         graphics_4.2.2     grDevices_4.2.2   
  grid_4.2.2         gridpattern_1.0.2  gtable_0.3.1      
  isoband_0.2.6      KernSmooth_2.23.20 labeling_0.4.2    
  lattice_0.20.45    lifecycle_1.0.3    magrittr_2.0.3    
  MASS_7.3.58.1      Matrix_1.5.1       memoise_2.0.1     
  methods_4.2.2      mgcv_1.8.41        munsell_0.5.0     
  nlme_3.1.160       pillar_1.8.1       pkgconfig_2.0.3   
  png_0.1.8          proxy_0.4.27       R6_2.5.1          
  RColorBrewer_1.1.3 Rcpp_1.0.9         rlang_1.0.6       
  s2_1.1.2           scales_1.2.1       sf_1.0.9          
  splines_4.2.2      stats_4.2.2        tibble_3.1.8      
  tools_4.2.2        units_0.8.1        utf8_1.2.2        
  utils_4.2.2        vctrs_0.5.0        viridisLite_0.4.1 
  withr_2.5.0        wk_0.7.1          

Thank you in advance!

trevorld commented 1 year ago

Yes, this is expected. You want to adjust pattern_scale and perhaps pattern_res instead. We never reverse engineered the "magick" pattern generation process and hence can't coherently specify a pattern_spacing parameter like we can with the "geometry" patterns...