Back to articles

How to write a custom function to generate multiple plots in R

How to Write a Custom Function to Generate Multiple Plots in RAn easy introduction to writing custom functionsA visual of a pair of hands typing on a laptop with code on the screen. Image by AuthorI always felt intimidated to write functions in R, since I was so comfortable using out-of-the box solutions that come with tidyverse. When I started coding in Python, I found myself writing more and more custom functions to replicate my favorite dplyr functions from R into Python.Learning how to write functions in Python has made me a better programmer in R, too. It’s helped me automate my work and ensure reproducibility. The most common use case I have for custom functions is to generate multiple plots in R.Reasons to write custom functions to generate plots in R:1. Automate reporting: Sometimes you have to build a report with the same type of visual (like a bar chart) for different variables. For example, I formerly worked for the Mayor of Los Angeles, Eric Garcetti, during the height of t
#plotly
#python
#testing
12 May 2023
vote
comment0