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

  • SEARCH
  • Home
  • 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 6934601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:58:54+00:00 2026-05-27T11:58:54+00:00

I am attempting to use faceting to generate multiple maps filled with different values.

  • 0

I am attempting to use faceting to generate multiple maps filled with different values.

I’ve created the simplified example below that reproduces both what I am trying to do and the result that I don’t expect from ggplot. I use the map of the United States and generate two hypothetical communities for the states. I can plot each community separately, but where I try to facet and generate them at the same time, I only get one map.

require(ggplot2)
require(maps)

map <- map_data("state")
states <- unique(map$region)

# generate some hypothetical communities    
runA <- data.frame(region=states, id="A",
                   community=rbinom(length(states),1,.5))
runB <- data.frame(region=states, id="B",
                   community=rbinom(length(states),1,.5))

membership <- rbind(runA, runB)

# plot an individual map of communities from run A
df <- merge(map, runA, by="region")
ggplot(df) +
  aes(long, lat, group=group) +
  coord_equal() +
  geom_polygon(aes(fill = as.factor(community)))

# likewise for B
df <- merge(map, runB, by="region")
ggplot(df) +
  aes(long, lat, group=group) +
  coord_equal() +
  geom_polygon(aes(fill = as.factor(community)))

# now instead do one plot with two maps from facetting on id
df <- merge(map, membership, by="region")
ggplot(df) +
  aes(long, lat, group=group, facets= id ~.) +
  coord_equal() +
  geom_polygon(aes(fill = as.factor(community)))

Ideally the last plot should have two maps, one showing the community in “A” and the other showing the community in “B”. Instead, the plot only shows one map and I am not even sure what is being mapped to the fill.

  • 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-05-27T11:58:55+00:00Added an answer on May 27, 2026 at 11:58 am

    You just specified the facets the wrong way. Do it like this instead and it’ll work fine:

    ggplot(df) +
      aes(long, lat, group=group) +
      coord_equal() +
      geom_polygon(aes(fill = as.factor(community))) +
      facet_grid(facets= id ~.)
    

    enter image description here

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

Sidebar

Related Questions

Attempting to use the data series from this example no longer passes the JSONLint
In attempting to use std::select1st from <functional> in a VS2008 project I found that
I am attempting to use XMLParse against content that is not valid xhtml. In
I am attempting to use the MediaStore.ACTION_VIDEO_CAPTURE in my app, see code below. However,
I am attempting to use the AutoComplete plugin for jQuery UI, specifically the multiple
I'm attempting to use mod_rewrite to redirect requests to 123.example.com/456/file.html to example.com/123/456/file.html . The
Attempting to use asp.net mvc's Action Result of File. So it would seem that
I'm attempting to use Dotfuscator 4.7.1000 to obfuscate a Silverlight library that is strongly
I'm attempting to use the sample broker that comes with ActiveMQ 5 with an
Attempting to use XStream's JavaBeanConverter and running into an issue. Most likely I'm missng

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.