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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:03:24+00:00 2026-06-09T15:03:24+00:00

I want additional ‘geoms’ to only apply to a subset of the initial data.

  • 0

I want additional ‘geoms’ to only apply to a subset of the initial data. I would like this subset to be from each units created by facets=~.

My trials using subletting of either the data or of the plotted variables leads to subsetting of the whole data set, rather than the subletting of the units created by ‘facets=~’ and in two different ways (apparently dependant on the sorting of the data).

This difficulty is appears with any ‘geom’ while using ‘facets’

library(ggplot2)

test.data<-data.frame(factor=rep(c("small", "big"), each=9),
                              x=c(c(1,2,3,3,3,2,1,1,1), 2*c(1,2,3,3,3,2,1,1,1)),
                              y=c(c(1,1,1,2,3,3,3,2,1), 2*c(1,1,1,2,3,3,3,2,1)))


factor x y
1   small 1 1
2   small 2 1
3   small 3 1
4   small 3 2
5   small 3 3
6   small 2 3
7   small 1 3
8   small 1 2
9   small 1 1
10    big 2 2
11    big 4 2
12    big 6 2
13    big 6 4
14    big 6 6
15    big 4 6
16    big 2 6
17    big 2 4
18    big 2 2


qplot(data=test.data,
      x=x,
      y=y,
      geom="polygon",
      facets=~factor)+
      geom_polygon(data=test.data[c(2,3,4,5,6,2),],
                   aes(x=x,
                       y=y),
                   fill=I("red"))

enter image description here

qplot(data=test.data,
      x=x,
      y=y,
      geom="polygon",
      facets=~factor)+
        geom_polygon(aes(x=x[c(2,3,4,5,6,2)],
                         y=y[c(2,3,4,5,6,2)]),
                     fill=I("red"))

enter image description here

  • 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-09T15:03:26+00:00Added an answer on June 9, 2026 at 3:03 pm

    The answer is to subset the data in a first step.

    library(ggplot2)
    library(plyr)
    
    test.data<-data.frame(factor=rep(c("small", "big"), each=9),
                          x=c(c(1,2,3,3,3,2,1,1,1), 2*c(1,2,3,3,3,2,1,1,1)),
                          y=c(c(1,1,1,2,3,3,3,2,1), 2*c(1,1,1,2,3,3,3,2,1)))
    
    subset.test<-ddply(.data=test.data,
                       .variables="factor",
                       function(data){
                         data[c(2,3,4,5,6,2),]})
    
    qplot(data=test.data,
          x=x,
          y=y,
          geom="polygon",
          facets=~factor)+
            geom_polygon(data=subset.test,
                         fill=I("red"))
    

    enter image description here

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

Sidebar

Related Questions

I want to associate additional data with each QTableWidgetItem inserted into the table, in
On my Wordpress blog, I want to show additional content to people from Finland
I have a string with this data: 2011-09-13 22:20:00 I want to have this
I want to be able to list only the directories inside some folder. This
I want to store additional information on my users (address, phone). Should I extend
I want to add additional criteria to the LEFT OUTER JOIN generated by the
I have following code and i want to pass additional parameter in JSON.getJSONfromURL() method
I am using ASP.net membership, but I want to store additional information for client
I want to add an additional roadblock in my application to prevent automating it
I want to inject one additional variable into the context of a view that

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.