C W
2020-Nov-17 17:43 UTC
[R] How to understand the mentality behind tidyverse and ggplot2?
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! [[alternative HTML version deleted]]
Bert Gunter
2020-Nov-18 18:28 UTC
[R] How to understand the mentality behind tidyverse and ggplot2?
This is not the place for tutorials (although I recognize that many responses and discussions do intersect tutoriality). If you do a web search on ggplot tutorials you will find many good ones. Or go to the RStudio website which links to resources, including Hadley Wickham's book, which is probably the most authoritative. Incidentally, ggplot is based on Leland WIlkinson's book "The Grammar of Graphics" that provided the blueprint for Wickham's software (his PhD project at Iowa State I believe). Cheers, Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Wed, Nov 18, 2020 at 9:37 AM C W <tmrsg11 at 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! > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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. >[[alternative HTML version deleted]]
Ben Tupper
2020-Nov-18 18:31 UTC
[R] How to understand the mentality behind tidyverse and ggplot2?
Hi, I feel your pain. As you have likely discovered yourself, there are just about 10^14 tutorials/posts/tips out there on ggplot2. See https://rseek.org/?q=+ggplot2+tutorial for example. Yikes! One resource I found most helpful when I started is https://evamaerey.github.io/ggplot_flipbook/ggplot_flipbook_xaringan.html#1. This is a terrific resource for getting the feel of layering-up. Hope you find it helpful. CHeers, Ben On Wed, Nov 18, 2020 at 12:37 PM C W <tmrsg11 at 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! > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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.-- Ben Tupper Bigelow Laboratory for Ocean Science East Boothbay, Maine http://www.bigelow.org/ https://eco.bigelow.org
ei m@iii@g oii iisse@@@
2020-Nov-18 18:49 UTC
[R] How to understand the mentality behind tidyverse and ggplot2?
RTFM, perhaps? Or even worse, buy his book? el ? Sent from Dr Lisse?s iPad Mini 5 On 18 Nov 2020, 20:39 +0200, Ben Tupper <btupper at bigelow.org>, wrote:> Hi, > > I feel your pain. As you have likely discovered yourself, there are > just about 10^14 tutorials/posts/tips out there on ggplot2. See > https://rseek.org/?q=+ggplot2+tutorial for example. Yikes! > > One resource I found most helpful when I started is > https://evamaerey.github.io/ggplot_flipbook/ggplot_flipbook_xaringan.html#1. > This is a terrific resource for getting the feel of layering-up. > > Hope you find it helpful. > > CHeers, > Ben > > On Wed, Nov 18, 2020 at 12:37 PM C W <tmrsg11 at 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! > > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > R-help at 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. > > > > -- > Ben Tupper > Bigelow Laboratory for Ocean Science > East Boothbay, Maine > http://www.bigelow.org/ > https://eco.bigelow.org > > ______________________________________________ > R-help at 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.[[alternative HTML version deleted]]
Bert Gunter
2020-Nov-18 19:34 UTC
[R] How to understand the mentality behind tidyverse and ggplot2?
I should have said: Have you worked through the Vignettes and examples?? Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Wed, Nov 18, 2020 at 9:37 AM C W <tmrsg11 at 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! > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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. >[[alternative HTML version deleted]]
Hadley Wickham
2020-Nov-18 19:37 UTC
[R] How to understand the mentality behind tidyverse and ggplot2?
I'd recommend two places to get started: * https://r4ds.had.co.nz/data-visualisation.html for a quick intro to ggplot2 (and the rest of the book explains the general tidyverse philosophy) * https://ggplot2-book.org for the full details of ggplot2. Hadley On Wed, Nov 18, 2020 at 11:37 AM C W <tmrsg11 at 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! > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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.-- http://hadley.nz
Duncan Murdoch
2020-Nov-18 20:38 UTC
[R] How to understand the mentality behind tidyverse and ggplot2?
On 17/11/2020 12:43 p.m., C W 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?Think of the pipe as pure syntactic sugar. It doesn't really do anything, it just lets you write "f(g(x))" as "x %>% g() %>% f()" (where the parens "()" are optional). Read it as "Take x and pass it to g(); take the result and pass it to f()", which is exactly how you'd read "f(g(x))". The pipe presents it in the same order as in English, which sometimes makes it a bit easier to read than the mathematical notation. There's a lot more to tidyverse ideas besides the pipe. The overview is in the "Tidyverse Manifesto" (a vignette in the tidyverse package), and details are in Grolemund and Wickham's book "R for Data Science".> > With ggplot2, I just don't understand how it is organized. Take this code:ggplot2 is much harder to understand, but Wickham's book "ggplot2: Elegant Graphics for Data Analysis" gives a really readable yet thorough description.> >> 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.Yes "aesthetic" was a really bad choice of word.> So, how does ggplot2 work? Could someone explain this for an old-school R > user?Not in one email, but hopefully the references (which are both available online for free, or in a bookstore at some cost) can help. Duncan Murdoch
John
2020-Nov-18 23:24 UTC
[R] How to understand the mentality behind tidyverse and ggplot2?
On Tue, 17 Nov 2020 12:43:21 -0500 C W <tmrsg11 at 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
Roy Mendelssohn - NOAA Federal
2020-Nov-18 23:33 UTC
[R] How to understand the mentality behind tidyverse and ggplot2?
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 at r-project.org> wrote: > > On Tue, 17 Nov 2020 12:43:21 -0500 > C W <tmrsg11 at 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 at 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 at 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.
Duncan Murdoch
2020-Nov-20 09:27 UTC
[R] How to understand the mentality behind tidyverse and ggplot2?
On 18/11/2020 3:38 p.m., Duncan Murdoch wrote:> On 17/11/2020 12:43 p.m., C W 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? > > Think of the pipe as pure syntactic sugar. It doesn't really do > anything, it just lets you write "f(g(x))" as "x %>% g() %>% f()" (where > the parens "()" are optional). Read it as "Take x and pass it to g(); > take the result and pass it to f()", which is exactly how you'd read > "f(g(x))". The pipe presents it in the same order as in English, which > sometimes makes it a bit easier to read than the mathematical notation. > > There's a lot more to tidyverse ideas besides the pipe. The overview is > in the "Tidyverse Manifesto" (a vignette in the tidyverse package), and > details are in Grolemund and Wickham's book "R for Data Science".Whoops, I got the title wrong: that's "The tidy tools manifesto". Duncan Murdoch> >> >> With ggplot2, I just don't understand how it is organized. Take this code: > > ggplot2 is much harder to understand, but Wickham's book "ggplot2: > Elegant Graphics for Data Analysis" gives a really readable yet thorough > description. > >> >>> 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. > > Yes "aesthetic" was a really bad choice of word. > >> So, how does ggplot2 work? Could someone explain this for an old-school R >> user? > > Not in one email, but hopefully the references (which are both available > online for free, or in a bookstore at some cost) can help. > > Duncan Murdoch >