Hi there!
Cats have always been a constant in my life — my cats, my family’s cats, friends’ cats, even the neighbours' cats. There’s no escaping the feline influence 🐈⬛!
As I write this, not much has changed. I’m completely surrounded by cuteness. Please, someone, save me.
Speaking of saving, let’s dive into that topic.
You can grab the dataset here, and then start by typing:
### Libraries ###
library(readr)
### Loading data ###
blue_tits <- read_csv("paste_the_path_to_the file_here")
# which should be sth along the lines of:
blue_tits <- read_csv("../data/blue_tits.csv")
I’ve already talked about organizing your digital workspace, but it’s worth emphasizing again:
You should create one main project folder — something like “Coding_Is_Fun” in your Documents — and within it, create three sub-folders: data, coding, and results. I also like to keep a fourth folder, which I’ve named doodling, though you might come across the term sandpit 🏖️. This folder is for "trash-but-not-trash" scripts — a place to dump all my shitty first scripts. If you’re not familiar with the concept of "shitty first drafts" (or scrips in our case), here’s a good piece on that topic: First Drafts by Austin Kleon.
I’m usually too attached to let these scripts go completely and occasionally (1 in 10 cases) I find myself double-checking something in them. However, they’re generally messy and definitely not something to share with colleagues.
Now, let’s create a very basic plot. We’re not going to worry about titles, axes or font size just yet. And don’t pay too much attention to the biological meaning of the data — I’ve randomized the dataset in some cases, so you may spot a few outliers that don’t make much sense (e.g., blue tit chicks typically don’t hatch 40 days after egg-laying!).
Here is the plot — “p” denotes that we want to visualise data as points:
plot(blue_tits$Laying_day, blue_tits$Hatching_day, type = "p")
Okay, I know it’s tempting to just click the “Export” button, it's quick and easy, but if we did that, this post would be way too short! So for now, let's pretend that button doesn’t exist.
Instead, we want to save our ugly plot as a 450x350px JPEG, by doing the following:
Clear the plot area using the broom icon.
Tell R where and how we want to save the plot:
jpeg("../results/bt_plot.jpg", width = 450, height = 350)
This might feel a bit counterintuitive, at least it does to me — we first define the file format and dimensions before plotting. Once we run this command, the plot will be saved in the results subfolder. If you’re unsure about how relative file paths work, check out my previous post on the topic.
Create the plot:
plot(blue_tits$Laying_day, blue_tits$Hatching_day, type = "p")
Close the file
dev.off()
This command ensures R properly saves the file so that our bt_plot doesn’t end up resembling Malevich’s Black Square. If R gets confused, you may need to run the command more than once, or clear the plot area and start over.
Ta-da! You should be able to see the plot by clicking on the right file in your results folder.
Now, here’s a little homework for you. And don’t cheat yourself — reading about something is one thing, but actually running the command is another! Try saving the plot in PDF, TIFF, or PNG format. I promise, it’ll jog your muscle memory and help it stick longer 😇.
Lately, I’ve been either spending my time in the lab, preparing DNA samples for sequencing (they're so tiny, yet require so much work 😮💨), or wading through a pile of emails. I now understand why academic supervisors either a) don’t reply to an email at all, b) only answer half the email or c) send a response that has nothing to do with your question.
But I promised my partner I’d surprise him with a fun fact he hasn’t heard yet, so here it is:
I already knew that bats are key pollinators of agave plants, meaning we can thank them every time we drink tequila 🍹. But recently, I learned that wasps, which feed on the sweet juice of ripened grapes in vineyards, leave microscopic yeasts on the grape's surface after their visit. Since wasps' stomachs are the perfect place for yeasts to shuffle their genes a bit, each wasp carries yeasts with a unique genetic make-up. Apparently, this is one of the reasons why each batch of wine tastes slightly differently!
Have a great evening,
Aga
PS: Here is the survey in which you can tell me what R topic you find particularly confusing and why you want to learn it so that we can shape this space together!