Supplying names to vars() in ggplot2.

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Supplying names to vars() in ggplot2.

Rolf Turner

I need to call ggplot() from another function with the names of the
faceting variables supplied as arguments to the calling function.  These
names (which are names of columns in the relevant data frame)
are given as character arguments, say "rowName" and "colName".
Suppose that rowName is equal to "clyde" and colName is equal to "irving".

I'd like to do something like

... + facet_grid(row=vars(rowName), col=vars(colName)) + ...

but this does not work.  For instance, vars(rowName) gives

> [[1]]
> <quosure>
> expr: ^rowName
> env:  global

I'd like to get the same thing as if I said vars(clyde) which gives

> <list_of<quosure>>
>
> [[1]]
> <quosure>
> expr: ^clyde
> env:  global

There *must* be some magic arcane incantation that I can apply to
rowName (and colName) to get what I want.  Mustn't there?

I tried things like vars(as.name(rowName)) --- nope, no help at all.

Can anyone help me out?

cheers,

Rolf Turner

--
Honorary Research Fellow
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Supplying names to vars() in ggplot2.

hadley wickham
See this new vignette in dev ggplot2:
https://ggplot2.tidyverse.org/dev/articles/ggplot2-in-packages.html

Hadley

On Saturday, November 16, 2019, Rolf Turner <[hidden email]> wrote:

>
> I need to call ggplot() from another function with the names of the
> faceting variables supplied as arguments to the calling function.  These
> names (which are names of columns in the relevant data frame)
> are given as character arguments, say "rowName" and "colName".
> Suppose that rowName is equal to "clyde" and colName is equal to "irving".
>
> I'd like to do something like
>
> ... + facet_grid(row=vars(rowName), col=vars(colName)) + ...
>
> but this does not work.  For instance, vars(rowName) gives
>
> [[1]]
>> <quosure>
>> expr: ^rowName
>> env:  global
>>
>
> I'd like to get the same thing as if I said vars(clyde) which gives
>
> <list_of<quosure>>
>>
>> [[1]]
>> <quosure>
>> expr: ^clyde
>> env:  global
>>
>
> There *must* be some magic arcane incantation that I can apply to rowName
> (and colName) to get what I want.  Mustn't there?
>
> I tried things like vars(as.name(rowName)) --- nope, no help at all.
>
> Can anyone help me out?
>
> cheers,
>
> Rolf Turner
>
> --
> Honorary Research Fellow
> Department of Statistics
> University of Auckland
> Phone: +64-9-373-7599 ext. 88276
>
> ______________________________________________
> [hidden email] 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/posti
> ng-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>


--
http://hadley.nz

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Supplying names to vars() in ggplot2.

Rolf Turner

On 18/11/19 2:28 AM, Hadley Wickham wrote:

> See this new vignette in dev ggplot2:
> https://ggplot2.tidyverse.org/dev/articles/ggplot2-in-packages.html
>
> Hadley

Yes!  Thank you.  Bottom line:  for what I want to do the syntax is

facet_grid(row=vars(.data[[rowName]]),col=vars(.data[[colName]]))

Thanks again.

cheers,

Rolf

> On Saturday, November 16, 2019, Rolf Turner <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>
>     I need to call ggplot() from another function with the names of the
>     faceting variables supplied as arguments to the calling function.
>     These names (which are names of columns in the relevant data frame)
>     are given as character arguments, say "rowName" and "colName".
>     Suppose that rowName is equal to "clyde" and colName is equal to
>     "irving".
>
>     I'd like to do something like
>
>     ... + facet_grid(row=vars(rowName), col=vars(colName)) + ...
>
>     but this does not work.  For instance, vars(rowName) gives
>
>         [[1]]
>         <quosure>
>         expr: ^rowName
>         env:  global
>
>
>     I'd like to get the same thing as if I said vars(clyde) which gives
>
>         <list_of<quosure>>
>
>         [[1]]
>         <quosure>
>         expr: ^clyde
>         env:  global
>
>
>     There *must* be some magic arcane incantation that I can apply to
>     rowName (and colName) to get what I want.  Mustn't there?
>
>     I tried things like vars(as.name <http://as.name>(rowName)) ---
>     nope, no help at all.
>
>     Can anyone help me out?

--
Honorary Research Fellow
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

______________________________________________
[hidden email] 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.