UM-R-for-EnvSci-Registered-Student / General-Discussion

Public repo for general discussion about the course and assignments
1 stars 0 forks source link

General Question - Patterned Bar Graph #23

Open josiecooke opened 3 years ago

josiecooke commented 3 years ago

Hi all,

I have searched a bit online but wasn't able to find a quick & relatively simple solution.

I would like to create patterns inside my grouped bar graphs (diagonal lines, dots, etc.) and avoid using different colours so that it is safe to print in black & white and remains easily distinguishable between the different bars. I figured I would ask as this is my first time actually having to use R for my own data and thought perhaps some of you have already come across this requirement! Image attached below from an excel bar graph for example.

Thanks

Screen Shot 2020-12-09 at 1 42 17 PM

peperg commented 3 years ago

Hey @josiecooke,

That is one of those few things that are unfortunatelly hard to do in ggplot. Fortunatelly the need for that is becoming less and less of a priority given that most people read papers on .pdf where colour is not a problem. There are still a few journals which are printed in paper and they will charge more to have the figures with colours in the printed version. Usually the online copy can have colour images for free, but i can see how the figures representing well in B&W can still be a plus. Fortunately, most of the commonly used palettes in ggplot were designed with that in mind. Viridis, for example maintains the differences between colours even in B&W (check the section where they show how the different Viridis palettes show under different types of colour blindness, as well as desaturated), so do most of the palettes in Brewer.

If you do still want to add texture, there are a couple of packages. Claus Wilke, who we have mentioned a couple of times during the course has the gtextures package, which can help you with it, but it would require having a figure of your texture hosted somewhere, so not 100% the most practical (although it can help with some unique uses).

From my limited experience, i would say that ggpattern is probably the easiest to use for the output you want, but i have not tested it extensibly, so i cannot give you a full review.

If you trie them, let me know how it goes!

Pepe