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

The Archive Base Latest Questions

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

I wonder if this is asking too much of ggplot. I’m trying to plot

  • 0

I wonder if this is asking too much of ggplot. I’m trying to plot some graphs over the geographical regions they relate to using facet_grid The outcome seems on track, but there are some problems getting the scale right, getting rid of the unused grid boxes. I wonder if anyone knows how to tweak it to work?

The example is based on the inbuilt US States dataset.

Any assistance appreciated!

    # My failed attempt to regional summary graphs plotted over the region centroid (to overlay onto map):
# example based on the States dataset

require(ggplot2)

# Approx centroid coordinates for the US regions - I created these as the information is missing from the dataset
lat <- c(32L, 42L, 42L, 32L, 42L, 42L, 43L, 32L, 32L, 32L, 42L, 42L, 43L, 43L, 43L, 43L, 32L, 32L, 43L, 32L, 43L, 43L, 43L, 32L, 43L, 42L, 43L, 42L, 43L, 43L, 42L, 43L, 32L, 43L, 43L, 32L, 42L, 43L, 43L, 32L, 43L, 32L, 32L, 42L, 43L, 32L, 42L, 32L, 43L, 42L)
lon <- c(-88L, -114L, -114L, -88L, -114L, -114L, -73L, -88L, -88L, -88L, -114L, -114L, -91L, -91L, -91L, -91L, -88L, -88L, -73L, -88L, -73L, -91L, -91L, -88L, -91L, -114L, -91L, -114L, -73L, -73L, -114L, -73L, -88L, -91L, -91L, -88L, -114L, -73L, -73L, -88L, -91L, -88L, -88L, -114L, -73L, -88L, -114L, -88L, -91L, -114L)

region.centres <- data.frame(lon = lon, lat = lat)

state.x77 <- data.frame(state.x77)
state.x77$State <- row.names(state.x77)
region <- data.frame(Region = as.character(state.region))
data <- data.frame(c(data.frame(state.x77), region, region.centres))

# I can plot a random summary graph for each region:

p <- ggplot(data, aes(Income, colour = 'red')) +
  geom_density(alpha = 0.2)

# But trying to plot onto centroid nearly works but results in loss of geographical positional accuracy
# and includes various graphs that fill the empty grid slots but are not necessary
p + facet_grid(lat ~ lon, space = "free", drop=T)

# How can I get uniform discrete graphs to sit over the centroid for each region?
  • 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-10T12:40:20+00:00Added an answer on June 10, 2026 at 12:40 pm

    Perhaps annotations would suit your use case better than faceting. Try the following after your own code. Annotations require a lot of manual fiddling, but should get the job done.

    library(maps)
    states = data.frame(map("state", plot=FALSE)[c("x", "y")])
    data.south = subset(data, lon == -88 & lat == 32)
    overlay = qplot(data.south$Income, geom="density", color="red")
    plot = (ggplot(states, aes(x, y))
            + geom_path()
            + annotation_custom(grob=ggplotGrob(overlay),
                                xmin=-88-2,
                                xmax=-88+2,
                                ymin=32-6,
                                ymax=32+6))
    
    print(plot)
    

    annotation_custom was added in ggplot2 0.9.0. See

    http://cloud.github.com/downloads/hadley/ggplot2/guide-col.pdf

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

Sidebar

Related Questions

Im trying to find best practices to write PHP. I just wonder is this
I see this question here, and it makes me wonder if what I'm asking
I wonder if this affects performance or memory consumption a lot. I need an
i wonder what this query means: $blogPost = Doctrine_Query::create()->from('BlogPost p')->where('p.slug = ?', 'doctrine-released')->execute(); could
I wonder is this a bug in chrome or jQuery, or am I misunderstanding
I was wonder if this would be possible and how to do it. I
I really wonder why this question hasn't popped up here so far. I have
Hi (sorry for my ugly english) I wonder if this is possible to retrieve
Possible Duplicate: What does new() mean? Like in title. I wonder what this syntax
I wonder how is this possible in groovy to start an array from the

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.