Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9260573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:55:40+00:00 2026-06-18T12:55:40+00:00

Interactively, this example works fine: p <- ggplot(mtcars, aes(mpg, wt)) + geom_point() p +

  • 0

Interactively, this example works fine:

p <- ggplot(mtcars, aes(mpg, wt)) + geom_point()
p + facet_grid(. ~ vs)

Now, make a function with a formula interface and use aes_string to do this same thing, and it doesn’t work (error is: Error in layout_base(data, cols, drop = drop) : At least one layer must contain all variables used for facetting):

tf <- function(formula, data) {
res <- as.character(formula[[2]])
fac2 <- as.character(formula[[3]][3])
fac1 <- as.character(formula[[3]][2])

# p <- ggplot(aes_string(x = fac1, y = res), data = data)
# p <- p + geom_point() # original attempt
p <- ggplot() # This is Joran's trick, but it doesn't work here
p <- p + geom_point(aes_string(x = fac1, y = res), data = data)
p <- p + facet_grid(.~fac2) # comment this out, and it works but
# of course is not faceted
}

p <- tf(formula = wt ~ am*vs, data = mtcars)

By Joran’s trick I refer to here, which is a similar question I posted recently. In this case ggplot2doesn’t see my faceting request. Making it facet_grid(".~fac2") had no effect. Suggestions? I’m continually out-witted by these things. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T12:55:42+00:00Added an answer on June 18, 2026 at 12:55 pm

    You can use as.formula and paste:

    p <- p + facet_grid(as.formula(paste(". ~", fac2)))
    

    In your example, this gives:

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I make an interactive function that interactively read a key from the
I use Wicket's AjaxFallbackLink in a number of places. This works fine for users,
I'm using rpy2 to do data analysis and plotting in python. It works fine
I'm following this example for an auto-scrolling behavior on a ListBox on WP7 Mango
I want to make a function that can determine the source code of how
BACKGROUND I'm doing an interactive art project for school. PROCESS For this project the
I'm a postgresql user and I'm trying to follow this : http://www.postgresql.org/docs/current/interactive/sql-createtrigger.html CREATE TRIGGER
I use R interactively from Org-mode - the keybinding C-x ' from within an
I'd like to write a Haskell program that uses GADTs interactively on a platform
Are there any howtos for using the PHP command line interactively? I found a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.