Suppose I have the following data set collected from a hypothetical survey:
name age homeowner favorite_color pets
Bill 45 Yes Blue (cat, dog, fish)
Mary 33 Yes Red (cat, dog)
Joe 55 Yes Blue (cat, bird, fish)
Sue 38 No Green (fish, bird)
Where each person is able to provide multiple responses to the type of pets that they own.
Is there an easy way to create a scatterplot of the following with ggplot2
?
x axis = homeowner
y axis = favorite_color
col = pets
Essentially, I'm looking to plot three categorical values. I'm having trouble trying to figure out how to best extract the nested vector data for pets. For the sake of simplicity, let's say they are only allowed to have one of each kind of pet.
At the intersection of (Yes, blue), I am looking to see a jittered plot with:
- 2 points for cat in the same color
- 2 points for fish in the same color
- 1 point for bird
- 1 point for fish
Any help you can provide here would be very much appreciated - very new to r.