R-ecology-lesson icon indicating copy to clipboard operation
R-ecology-lesson copied to clipboard

Inconsistent use of argument names in code examples of ggplot2

Open toms-coding opened this issue 2 years ago • 1 comments


Hi all, looking to make a minor contribution for my instructor training.

I find that in the “Data visualization with ggplot2” lesson, the argument names are included or not included a little inconsistently. For example, having code in an example like this:

gplot(data = surveys_complete, aes(x = weight, y = hindfoot_length)) + geom_point(alpha = 0.1)

followed immediately by this example:

gplot(data = surveys_complete, mapping = aes(x = weight, y = hindfoot_length)) + geom_point(alpha = 0.1, color = "blue")

Can be a little confusing for new learners. When I first did the lessons some time ago I know I was told that yes, you don’t need to include “argument = “ provided they are in the correct order. However, if you are not familiar and all that is being added is colour then it’s easy to think “why is ‘mapping =’ now gone, did that matter?”. I think maybe it would be a little better to keep the lines of code exactly the same apart from just the extra argument added

May just be me, I am a fan of consistency in coding :-)

Thoughts welcome Tom


toms-coding avatar Jun 06 '22 08:06 toms-coding

Hi @toms-coding, thank you for your suggestion! The use of the mapping = keyword is indeed quite inconsistent throughout the chapter. It disappears and reappears from example to example. This could cause some confusion. Calling the ggplot functions with the aes() as first argument is such a frequent "pattern" that I think it's worth memorizing it, even for beginners. Perhaps we should explain this in the beginning of the chapter and then remove the mapping = keyword afterwards?

Teebusch avatar Jun 10 '22 09:06 Teebusch