Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sheila's blog - Mapping my journey in R #266

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
---
title: "Mapping my R journey so far: ten things that I have done along the way"
format: html
editor: visual
---

![An abstract textile art piece symbolising my non-linear R learning journey - with overlapping and convoluted pathways, dead ends, and roadblocks along the way[^1].](R%20textile%20map.jpg){fig-alt="Textile art piece showing a map with the letter R - for decorative purposes only" fig-align="center" width="384"}

[^1]: I made this abstract textile art piece to accompany the blog post. This is inspired by existing real and abstract maps. It uses various textiles and materials, many of them recycled or upcycled (thread, cord, twine, elastic, and fabric remnants). I created and outlined a basic map shape which I built on and embellished using embroidery, weaving and applique techniques. The messy or 'wrong' features of the artwork have been intentionally kept in, as it helps to symbolise the messiness of the R learning journey.


This blog post follows up from a recent talk I gave at coffee and coding about my experiences of learning how to code using Rstudio. Here I build on that talk to share some more reflections and advice for others who are starting out on their R learning journey.

1. **I faced up to my fears**

I have tried to learn R a few times over several years, with mixed success. When I first tried learning it a few years ago, I didn't get very far past a very basic level. The second time, I was going through a crisis of confidence about my ability, and so difficulties with learning R, I thought it was more 'proof' that I couldn't do it. I tried again, and got to the stage of making a plot with the [mtcars](https://cran.r-project.org/web/packages/explore/vignettes/explore-mtcars.html) dataset that comes with Rstudio, and soon after that I got swept up in the demands of everyday life. Gradually my work moved away from the world of quantitative data and I had fewer opportunities to use R in my everyday work. Still, in the back of my mind I had this strange push-pull feeling of both wanting to avoid R, but also wondering what it would have been like if I had persisted with learning it.

A couple of years later, when I started my job here at the Strategy Unit, I heard about the NHS-R community, and it made me think about learning R again. I tried to join in with Advent of Code. But I couldn't understand a lot of what was going on, and when I tried to do some of the exercises, I immediately hit some hurdles with getting R and Rstudio set up on my computer, and those old negative feelings resurfaced.

After some failed attempts at teaching myself the basics, I thought I'd try something different to see if I could slowly recondition myself to look forward to using R. In December 2023 I came across the [aRtsy](https://cran.r-project.org/web/packages/aRtsy/readme/README.html) package. I was amazed by the colourful and intricate images that it could produce. But better still, all of the code was there on the website for me to make my own images[^3]. I decided to try and make a couple of plots, copying and pasting the code, and making very small changes to try and change the output.

[^3]: I note that my excitement about this generative art package was before AI image generation became as ubiquitous and controversial as it has become, especially in relation to artwork.

![A nebula generated using the [aRtsy](https://cran.r-project.org/web/packages/aRtsy/readme/README.html) package and the [canvas_nebula](https://koenderks.github.io/aRtsy/#nebula) function](Nebula.jpg)

I also discovered colour palettes such as those in the [wesanderson](https://github.com/karthik/wesanderson) package, and tried using them on some plots. I soon found that my fear of R was quickly being replaced by a geeky fascination with all of the beautiful things that R could make with only a few lines of code. It felt low-stakes, because the worst that would happen if the code didn't work would be that I would get an error message. Suddenly, I was no longer dreading opening up R, and the process of coding felt less intimidating. This process of exploration had opened up a wealth of possibilities of what I could potentially do with R.

2. **I approached learning R like I would approach learning any other language**

Quite early on, I realised that learning coding in R was a lot like learning a new language, so I approached it in the same way. This meant learning some of the key words and phrases, and getting exposure to the language by reading, listening and watching, and spending time with people who were using it, and speaking and writing the language. I would go along to Coffee and Coding sessions and not really understand much of what was going on. It had an incremental effect and over time, the more I absorbed, the more familiar I became with the words. When I would listen to a talk or coffee and coding session, I always made sure that I thought of a question, so that I could learn something new.

3. **I set myself a goal and structured my learning to reach it**

I had an idea of a skill I could learn in R that would help me to produce a plot to accompany a case study report I was making. I knew it would probably be difficult, but wanted to check how feasible this would be for me as a beginner. My mentor explained that making a choropleth map was probably one of the most tricky skills to learn, but that he thought I could learn, and that he and other colleagues in the data science team would

This sounded like an achievable goal

I was quite keen to make the maps to illustrate what I was writing in the report, so I set myself the goal of trying to learn how to make a map by the end of the year. I kept chipping away at it and celebrated my small wins, even the tiny ones, until I achieved the goals I set for myself.

4. **I figured out how I learn best**

This involved listening to R tutorials on YouTube, working through books, trying out online coding courses, looking up how to do things on google, and asking my colleagues and mentors for advice about what resources I should look at, and what to avoid.

I realised that chipping away at it, doing an hour here and there consistently, was the best approach for me specifically, with some bigger blocks of time (around 2-3 hours) where I could just spend some time trying out different things to get the code to work properly. A combination of both of those things, over about a year, have helped me to pick up lots of skills along the way. I also found that having structure was really helpful.

One common roadblock that I came across was that often tutorials were not written in a way that I could reproduce the code or access the data, or were written in highly technical language, which meant that I had to go away and learn some key concepts to be able to understand the documentation. Over time I built up a mind map of key areas of Rstudio that I wanted to learn, and used it as a checklist to monitor my progress.

An important part of the learning journey for me has been gradually building up a vocabulary of words and concepts in Rstudio, so that I could better navigate any teaching materials. It helped me to both know what key words to search for, and how to understand what the help pages or tutorials were saying.

5. **I applied what I was learning to real data**

I realised that I learned well when I could apply my learning to real data. I have practiced using the inbuilt datasets in r, the palmerpenguins dataset, and the datasets that are referred to in R4DS.

Most recently, I have used the data that was most relevant to my work, from the UK [Census](https://www.ons.gov.uk/census). Figuring out the data and understanding it has been helpful for learning some of the more detailed skills.

6. **I found a supportive community**

The great thing about R is that it is free and open source. This lends itself well to communities of people who are both learning it and keen to teach others about it. When I joined the SU's [Coffee and Coding](https://the-strategy-unit.github.io/data_science/blogs/posts/2024-05-13_one-year-coffee-code/) sessions and [NHS-R community's Coffee and Code](https://nhsrway.nhsrcommunity.com/community-handbook.html#coffee-and-coding), I felt like a small child asking very silly questions, but to my surprise, all of the people I have met have been keen to help me learn. I learned to recognise and value the people in those communities who would invite questions, celebrate progress with learning skills in R and coding, and make time to help beginners and other people wanting to learn. Another lesson for me has been how encouraging it is to spend time with people who are extremely skilled and experienced at their job, and yet they are willing to spend time helping a beginner to solve a problem, even if it is something that requires some trial and error to figure out.

7. **I looked for inspiration to encourage me to keep going when I got stuck**

One of my worries about trying to learn R was that learning new things could take me more time at my age, and now I was several years older than I was last time I tried. But I was fairly confident that there must have been other people out there who had successfully learned how to code when they were my age or older. This led to a fascinating rabbit hole of learning about the history of women in coding[^4], and people who had successfully learned and used coding in their later life. I bookmarked these stories so that I could revisit them on the days where I was having a difficult time understanding a particular concept or getting my code to work.

[^4]: Historically, women were involved in coding, but their work was devalued. There is more information at XXX. If you are interested in watching a film about this topic, you may be interested in watching the movie Hidden Figures, based on the lives of astrophysicists Katherine Johnson, Dorothy Vaughan, and Mary Jackson.

8. **I embraced failure and started using it as a tool for learning**

Over time I understood that failure is part of the learning journey, and a helpful tool for the learning process itself. If I could figure out what didn't work, that often gave me information about what had gone wrong. This information was useful as it either gave me information about what I needed to fix, or gave me the words and concepts I could look into to solve the problem.

Sometimes seemingly minor coding errors produced hilariously terrible maps. Inspired by the [Terrible Maps](https://www.instagram.com/terriblemap/p/DCh2NhfB2JX/) social media pages, I created a folder to save some of the failed maps that I accidentally produced while trying to learn how to code specific features of my maps. These failures would often be useful: as well as making me laugh, they would often shift my mood away from frustration. Most of the time they would help me get unstuck by giving me information about what had gone wrong, or the words and concepts that I could research further to understand the problem and how to solve it.

![This is an example of one of the terrible maps I accidentally made, where the map ended up so small it could have been a data point, the x axis was squished, the y axis stretched to south of the equator, and one of the map markers, which was supposed to be located in the North of England, ended up somewhere in the Atlantic Ocean](Terrible%20map.png){fig-align="center"}

9. **I *made it sew***

Throughout my R learning journey, I have found that coding has been a useful conduit for my creativity, and similarly, my creative projects outside of work have been a catalyst for learning some key concepts in coding[^5]. I realised this a few months ago when my friend got me a beginner's embroidery kit, and as I learned how to make stitches and followed the pattern, I had a breakthrough about the problem I had gotten stuck with earlier in the day when trying to troubleshoot some code for one of my maps. I realised that just like with embroidery, I needed to approach the coding for the map in [layers](https://ggplot2.tidyverse.org/reference/layer_geoms.html#:~:text=In%20ggplot2%2C%20a%20plot%20in,displayed%2C%20not%20what%20is%20displayed.). I approached the process like I would for an art project[^6], to identify what I needed to do to adequately visualise both types of data that I wanted to include in the map[^7].

[^5]: This has also worked the other way around, as my newest creative endeavour is to learn about sewing, and the learning journey is just as intimidating, meticulous and complicated as it was for learning R. Now that I've learned some basics in R, I know that I can apply some of the same principles to learn sewing, and similarly, there are scores of supportive communities of skilled people who are keen to share their learning with new learners.

[^6]: Throughout the journey I have realised that thinking about the problem like an artist has been very helpful, because it gives me a different perspective, and allows me to use a similar iterative approach, and to trust the process. For example, when I have been learning about map aesthetics, I have approached the coding process by first writing a basic chunk of code and making small adjustments to it to understand what this does to change the plot.

[^7]: I wanted my choropleth maps to show both the population density and the underlying terrain. To do this, I needed to find out how to superimpose both types of data clearly.\
I used the [colorbrewer2](https://colorbrewer2.org/#type=sequential&scheme=BuGn&n=3) tool to test out some different colour palettes, and changed the opacity and terrain to look at what kind of colours worked best to show the choropleth data but also the terrain underneath. The tool let me test this on an example map and find out the hexadecimal colour codes for the colours in the palettes. I took a screenshot of some map tiles on openstreetmap, and digitally superimposed the palettes over them. I experimented with opacity and colour palettes until I found a setup that would likely work for my particular map. Then I adjusted the aesthetics in my R code by choosing a palette with similar colours.

10. **I've started learning about how to stay involved in the community**

A year on, I've come full circle. When I first started my learning journey, the kindness and helpfulness of the community was such a contrast to what I was expecting, that I was first refreshed, then overwhelmed, and then guilty. I soon realised that I it would be sensible to channel these feelings into learning as best I could, so that I could then become one of those people who help others in the community to learn.

As I write this, the year is coming to a close, and it has been a year since I re-started my R learning journey in earnest. Attending the RPYSOC conference in November this year reminded me of the warm sense of collaboration and community in NHS-R and NHS.pycom. My aim for the following year and beyond is to build on the skills I have learned so far, which will allow me to continue my journey of learning R, and to contribute to the communities that helped me find my way.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading