Exploring Cleaner Shrimp Color Vision Capabilities Using R


Graduate Students: Eleanor Caves & Patrick Green, Department of Biology

Faculty: Sönke Johnsen

Course: Bio190S, Sensory Systems: Sight, Taste, Smell, Touch, Sound, and Beyond 

A basic understanding of how to manipulate, analyze, and display large datasets is an essential skill in the life sciences. Sometimes, especially motivated students can teach themselves to code using online tutorials or relevant textbooks; however, using real data is often a tricky, messy affair. Thus, introducing students to the concepts of coding languages, and showing them the diversity of tasks that can be accomplished using a flexible coding scheme like R, is an important step in the training of any future scientist.

The aim of our data expeditions course was to give students in Bio 190S-0.2, a summer session course in sensory systems, an introduction to how real data may actually look and how they may actually be analyzed. Over the course of a two-hour class session, 16 students ranging from 16-22 years old were given the opportunity to explore a dataset on the color vision capabilities of three species of cleaner shrimp.


  • What are the color vision capabilities of cleaner shrimp?
  • Do different species of cleaner shrimp differ in their color vision?
  • Given our knowledge of cleaner shrimp visual physiology, what limits does this place on what parts of their world they can or cannot perceive, and how does this inform our hypotheses regarding their interactions with each other and with other species? 

The Dataset

The data were collected by Eleanor Caves as part of her doctoral thesis to investigate the color vision capability of these three species of cleaner shrimp. Cleaner shrimp are colorful crustaceans that are an important part of the health of coral reef ecosystems, as they provide “cleaning services” to reef fish by removing ectoparasites from fish. The ultimate goal of this project was to investigate how cleaner shrimp perceive the color patterns of both their conspecific cleaner shrimp and their fish partners, as part of a larger project to understand the evolution of cooperation between different species. The data set we used in class describes the dark-adapted spectral sensitivity (i.e. color vision capability, or sensitivity to different wavelengths of light) in three species of cleaner shrimp. From six individuals from each species, we documented the collective response of photoreceptors in the eye to wavelengths of light at 10 nanometer intervals (350-610nm), during Summer 2014, using a technique called electroretinography (ERG). ERG involves inserting a metal microelectrode into the eye of a live animal and then exposing the eye to different colors of light, to record the response of the eye to that light. Each row in the dataset is ERG data for a single individual at a specific wavelength, i.e. the normalized magnitude of the response of the eye (between 0 and 1) to that wavelength of light. Because we had 27 wavelength values at which we tested spectral sensitivity for each individual, there are 27 rows of data per individual, of 6 individuals for each of three species. There are four columns in the dataset, representing wavelength (every 10-nm), species (three total), individual ID (1-6 for each species), and ERG response.

Download the dataset

In-Class Exercises

In class, we gave the students an introduction to the ecology of cleaner shrimp, and asked them to make predictions about their color vision capability based on what they knew about their interactions with other cleaner shrimp and coral reef fish, as well as their habitat. We then helped students download R and R Studio, and taught students how to upload a dataset and explore the structure and content of that dataset using various commands. We then worked through subsetting and indexing data to isolate data from a single species or individual; plotting data and working with par functions to change the color or shape of data points, add best fit lines, and change line width and type; lowess smoothing functions to create smooth spectral sensitivity curves; basic functions to help isolate the wavelength of maximal response for each individual of each species; and finally, calculating the mean and standard deviation spectral sensitivity peak for each species and placing that information in a table for export. The final product that the students created in class is shown below, and represents a figure of spectral sensitivity for each species, as well as a table of mean and standard deviation peak sensitivity.

Download the R script

At the end of class, students compared their results to the published manuscript that resulted from these data (Caves et al., 2016), and wrote one-paragraph reflections on what they learned about cleaner shrimp vision, and what they did or did not enjoy about learning to code. The feedback was overwhelmingly positive, with students saying that this experience was novel and something that they hope to use later in their lives.

A few quotes from student memos include:

“The class today was challenging with all the coding stuff. It never occurred to me that I would need to learn how to code, but I am glad that I get to learn this. I think R would be also useful in the future study when we need to deal with data.”

“Today we learnt to use R Studio. It is my first time trying to code, and I think it is pretty interesting to do it. It is really hard to remember the language to command R to do its work, but now I understand how to use it to do similar things we have done today. I will try to use R to make plots in my future research.”

“The activity is so cool, and not so challenging. I hope I can help a lot more about coding in the future!”

"This activity was very challenging, but I had a lot of fun doing it. It was actually easier than I expected, since coding seems so out of reach when you don’t know what is happening or what the terms mean. I could definitely use R in the future for projects where I am required to use data, and probably impress my teachers! I’ve had projects from school where this would have been a really useful tool to use.” 


Eleanor Caves or Patrick Green
eleanor.caves@duke.edu or patrick.a.green@duke.edu


Data Expeditions
Genomics and the Life Sciences