Re: [R] make a lattice dotplot with symbol size proportional to a variable in the plotted dataframe
... and see also Section 3.5, Scope of Variables in the "R Language Definition" manual that ships with R. Cheers, Bert On Wed, Nov 8, 2023 at 8:06 AM Deepayan Sarkar wrote: > On Wed, 8 Nov 2023 at 10:56, Christopher W. Ryan via R-help > wrote: > > > > Very helpful, Deepayan, and educational. Thank you. > > > > What does NSE stand for? > > Non-standard evaluation, used widely in formula-interface functions as > well as the tidyverse. with() in my example is a less nuanced version > of this. See > > http://adv-r.had.co.nz/Computing-on-the-language.html > > https://developer.r-project.org/nonstandard-eval.pdf > > Best, > -Deepayan > > > > Thanks, > > Chris > > > > Deepayan Sarkar wrote: > > > > > > --Chris Ryan > > > > __ > > R-help@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. > > __ > R-help@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]] __ R-help@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.
Re: [R] make a lattice dotplot with symbol size proportional to a variable in the plotted dataframe
On Wed, 8 Nov 2023 at 10:56, Christopher W. Ryan via R-help wrote: > > Very helpful, Deepayan, and educational. Thank you. > > What does NSE stand for? Non-standard evaluation, used widely in formula-interface functions as well as the tidyverse. with() in my example is a less nuanced version of this. See http://adv-r.had.co.nz/Computing-on-the-language.html https://developer.r-project.org/nonstandard-eval.pdf Best, -Deepayan > Thanks, > Chris > > Deepayan Sarkar wrote: > > > > --Chris Ryan > > __ > R-help@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. __ R-help@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.
Re: [R] make a lattice dotplot with symbol size proportional to a variable in the plotted dataframe
Non-standard evaluation On 2023-11-08 10:56 a.m., Christopher W. Ryan via R-help wrote: Very helpful, Deepayan, and educational. Thank you. What does NSE stand for? Thanks, Chris Deepayan Sarkar wrote: --Chris Ryan __ R-help@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. __ R-help@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.
Re: [R] make a lattice dotplot with symbol size proportional to a variable in the plotted dataframe
Very helpful, Deepayan, and educational. Thank you. What does NSE stand for? Thanks, Chris Deepayan Sarkar wrote: > > --Chris Ryan __ R-help@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.
Re: [R] make a lattice dotplot with symbol size proportional to a variable in the plotted dataframe
Handling NSE in these kinds of examples is a pain in lattice. I would suggest using with() and dropping the data argument for simple examples, e.g., dd |> mutate(new.proportion = las/total, new.bubble = total/100) |> with(dotplot(agency ~ new.proportion, pch = 16, cex = new.bubble)) But if you care about multi-panel plots, you also need to be careful about making sure that the 'cex' values get split properly. This is done generally using the 'subscripts' argument provided to panel functions, so something like this should be safer: panel.bubble <- function(x, y, cex, ..., subscripts) { panel.dotplot(x, y, cex = cex[subscripts], ...) } dd |> mutate(new.proportion = las/total, new.bubble = total/100) |> with(dotplot(agency ~ new.proportion, pch = 16, cex = new.bubble, panel = panel.bubble)) Best, -Deepayan On Tue, 7 Nov 2023 at 11:03, Christopher Ryan via R-help < r-help@r-project.org> wrote: > Hello. My question is in the subject line. Using R 4.1.3 on Windows 10. > Commented MWE below. Thanks. > > --Chris Ryan > > > > library(dplyr) > library(lattice) > > ## fabricate a dataframe > dd <- data.frame(agency = sample(LETTERS, size = 5), > total = sample(100:200, size = 5), > las = sample(20:40, size = 5)) > dd <- dd %>% mutate(proportion = las/total, bubble = total/100) > > > ## attempt to make a dotplot with symbol size proportional > ## to the variable named total > > dotplot(agency ~ proportion, pch = 16, cex = bubble, data = dd) > ## object 'bubble' not found > > dotplot(agency ~ proportion, pch = 16, cex = dd$bubble, data = dd) > ## works > > > > ## also works in two commands > external.bubble <- dd$bubble > dotplot(agency ~ proportion, pch = 16, cex = external.bubble, data = dd) > > > > ## but how to chain it with pipes, dplyr-style, > ## modifying the dataframe and then > ## using the modified version in dotplot, all in one chain? > > dd %>% mutate(new.proportion = las/total, new.bubble = total/100) %>% > dotplot(agency ~ new.proportion, pch = 16, cex = new.bubble, data = .) > ## object 'new.bubble' not found > > > dd %>% mutate(new.proportion = las/total, new.bubble = total/100) %>% > dotplot(agency ~ new.proportion, pch = 16, cex = .$new.bubble, data = > .) > ## the .$new.bubble syntax seems to work, but I've never > ## used or seen that before, and it seems weird. > ## Is there a "proper" syntax? > > [[alternative HTML version deleted]] > > __ > R-help@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]] __ R-help@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.
[R] make a lattice dotplot with symbol size proportional to a variable in the plotted dataframe
Hello. My question is in the subject line. Using R 4.1.3 on Windows 10. Commented MWE below. Thanks. --Chris Ryan library(dplyr) library(lattice) ## fabricate a dataframe dd <- data.frame(agency = sample(LETTERS, size = 5), total = sample(100:200, size = 5), las = sample(20:40, size = 5)) dd <- dd %>% mutate(proportion = las/total, bubble = total/100) ## attempt to make a dotplot with symbol size proportional ## to the variable named total dotplot(agency ~ proportion, pch = 16, cex = bubble, data = dd) ## object 'bubble' not found dotplot(agency ~ proportion, pch = 16, cex = dd$bubble, data = dd) ## works ## also works in two commands external.bubble <- dd$bubble dotplot(agency ~ proportion, pch = 16, cex = external.bubble, data = dd) ## but how to chain it with pipes, dplyr-style, ## modifying the dataframe and then ## using the modified version in dotplot, all in one chain? dd %>% mutate(new.proportion = las/total, new.bubble = total/100) %>% dotplot(agency ~ new.proportion, pch = 16, cex = new.bubble, data = .) ## object 'new.bubble' not found dd %>% mutate(new.proportion = las/total, new.bubble = total/100) %>% dotplot(agency ~ new.proportion, pch = 16, cex = .$new.bubble, data = .) ## the .$new.bubble syntax seems to work, but I've never ## used or seen that before, and it seems weird. ## Is there a "proper" syntax? [[alternative HTML version deleted]] __ R-help@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.