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 9205349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:55:51+00:00 2026-06-17T23:55:51+00:00

Possible Duplicate: ggplot – facet by function output ggplot2 ‘s facets option is great

  • 0

Possible Duplicate:
ggplot – facet by function output

ggplot2‘s facets option is great for showing multiple plots by factors, but I’ve had trouble learning to efficiently convert continuous variables to factors within it. With data like:

DF <- data.frame(WindDir=sample(0:180, 20, replace=T), 
                 WindSpeed=sample(1:40, 20, replace=T), 
                 Force=sample(1:40, 20, replace=T))
qplot(WindSpeed, Force, data=DF, facets=~cut(WindDir, seq(0,180,30)))

I get the error : At least one layer must contain all variables used for facetting

I would like to examine the relationship Force~WindSpeed by discrete 30 degree intervals, but it seems facet requires factors to be attached to the data frame being used (obviously I could do DF$DiscreteWindDir <- cut(...), but that seems unecessary). Is there a way to use facets while converting continuous variables to factors?

  • 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-17T23:55:52+00:00Added an answer on June 17, 2026 at 11:55 pm

    Making an example of how you can use transform to make an inline transformation:

    qplot(WindSpeed, Force,
          data = transform(DF,
                           fct = cut(WindDir, seq(0,180,3))),
          facets=~fct)
    

    You don’t “pollute” data with the faceting variable, but it is in the data frame for ggplot to facet on (rather than being a function of columns in the facet specification).

    This works just as well in the expanded syntax:

    ggplot(transform(DF,
                     fct = cut(WindDir, seq(0,180,3))),
           aes(WindSpeed, Force)) +
      geom_point() +
      facet_wrap(~fct)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Generate multiple graphics from within an R function I am using this
Possible Duplicate: Annotating text on individual facet in ggplot2 I am working on a
Possible Duplicate: Generic methods and multiple constraints I need a generic function that has
Possible Duplicate: Can main function call itself in C++? I found this problem very
Possible Duplicate: How to use an image as a point in ggplot? Is it
Possible Duplicate: Is it possible to gain access to the closure of a function?
Possible Duplicate: Why does my cout output not appear immediately? I have a very
Possible Duplicate: left align two graph edges (ggplot) I am trying to put two
Possible Duplicate: List of ggplot2 options? I have a pretty basic question on ggplot2.
Possible Duplicate: Variable doesn’t get returned from AJAX function I have this function: function

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.