[R] How to understand the mentality behind tidyverse and ggplot2?

Roy Mendelssohn - NOAA Federal roy@mende|@@ohn @end|ng |rom no@@@gov
Thu Nov 19 00:33:18 CET 2020


Personally I liked two workshops Thomas Lin Pedersen gave:

https://www.youtube.com/watch?v=h29g21z0a68
https://www.youtube.com/watch?v=0m4yywqNPVY&t=5219s

-Roy

> On Nov 18, 2020, at 3:24 PM, John via R-help <r-help using r-project.org> wrote:
> 
> On Tue, 17 Nov 2020 12:43:21 -0500
> C W <tmrsg11 using gmail.com> wrote:
> 
>> Dear R list,
>> 
>> I am an old-school R user. I use apply(), with(), and which() in base
>> package instead of filter(), select(), separate() in Tidyverse. The
>> idea of pipeline (i.e. %>%) my code was foreign to me for a while. It
>> makes the code shorter, but sometimes less readable?
>> 
>> With ggplot2, I just don't understand how it is organized. Take this
>> code:
>> 
>>> ggplot(diamonds, aes(x=carat, y=price)) +
>>> geom_point(aes(color=cut)) +  
>> geom_smooth()
>> 
>> There are three plus signs. How do you know when to "add" and what to
>> "add"? I've seen more plus signs.
>> 
>> To me, aes() stands for aesthetic, meaning looks. So, anything
>> related to looks like points and smooth should be in aes().
>> Apparently, it's not the case.
>> 
>> So, how does ggplot2 work? Could someone explain this for an
>> old-school R user?
>> 
>> Thank you!
>> 
> A really short form is to consider that ggplot2 syntax defines an
> object, and then additional simply adds to it, which is what all the
> plus signs are.  Ideally, you can start a ggplot call with a
> designation of a target:
> 
> Instead of:
> ggplot(diamonds, aes(x=carat, y=price)) + ...
> 
> use something like"
> 
> fig1 <- ggplot(diamonds, aes(x=carat, y=price)) + ...
> 
> This creates an environment object that can then be further modified.
> Learning the syntax is a chore, but the output tends to be fine,
> especially for publications and final graphics. One the other hand it's
> slower and fussier than some of the more traditional approaches, which
> are what I would prefer for EDA. 
> 
> JWDougherty
> 
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

**********************
"The contents of this message do not reflect any position of the U.S. Government or NOAA."
**********************
Roy Mendelssohn
Supervisory Operations Research Analyst
NOAA/NMFS
Environmental Research Division
Southwest Fisheries Science Center
***Note new street address***
110 McAllister Way
Santa Cruz, CA 95060
Phone: (831)-420-3666
Fax: (831) 420-3980
e-mail: Roy.Mendelssohn using noaa.gov www: https://www.pfeg.noaa.gov/

"Old age and treachery will overcome youth and skill."
"From those who have been given much, much will be expected" 
"the arc of the moral universe is long, but it bends toward justice" -MLK Jr.



More information about the R-help mailing list