datacarpentry / R-ecology-lesson

Data Analysis and Visualization in R for Ecologists
https://datacarpentry.org/R-ecology-lesson/
Other
314 stars 508 forks source link

Inconsistent use of argument names in code examples of ggplot2 #802

Closed toms-coding closed 4 months ago

toms-coding commented 2 years ago

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


Teebusch commented 2 years ago

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?

tobyhodges commented 4 months ago

Thanks both for contributing to this discussion. The lesson underwent a major update and reorganisation when https://github.com/datacarpentry/R-ecology-lesson/pull/887 was merged. As this issue relates to content in a version of the lesson before that update took place, I will close it. Please open a new issue if you believe that some or all of the changes being discussed here remain relevant to the redesigned lesson, linking to this thread where appropriate.