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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:10:44+00:00 2026-06-03T19:10:44+00:00

I have a similar problem as @Mike in this question . The question is

  • 0

I have a similar problem as @Mike in this question. The question is how to set the outline colors of the regions in a map plot.

The proposed solution there is to add a geom_polygon to plot over the borders. This works, as long as the whole area is plotted. When trying try to restrict to a sub-area, the polygons get drawn oddly (presumably because some vertices get dropped). Using the standard geom_map example:

# Create example data
ids <- factor(c("1.1", "2.1", "1.2", "2.2", "1.3", "2.3"))
values <- data.frame(id = ids, value = c(3, 3.1, 3.1, 3.2, 3.15, 3.5))
positions <- data.frame(
  id = rep(ids, each = 4),
  x = c(2, 1, 1.1, 2.2, 1, 0, 0.3, 1.1, 2.2, 1.1, 1.2, 2.5, 1.1, 0.3, 0.5, 1.2, 2.5, 1.2, 1.3, 2.7, 1.2, 0.5, 0.6, 1.3),
  y = c(-0.5, 0, 1, 0.5, 0, 0.5, 1.5, 1, 0.5, 1, 2.1, 1.7, 1, 1.5, 2.2, 2.1, 1.7, 2.1, 3.2, 2.8, 2.1, 2.2, 3.3, 3.2)
)

# Plot data
ggplot(values, aes(fill = value)) + 
    geom_map(aes(map_id = id), map = positions) +
    geom_polygon(aes(x,y,group=id), fill = NA, colour = 'red', data = positions) +
    expand_limits(positions) +
    ylim(0, 3)

A possible workaround is using the colour aesthetic in geom_map and then manually choose the outline color with scale_colour_manual, as follows:

ggplot(values, aes(fill = value)) + 
    geom_map(aes(map_id = id, colour = 'white'), map = positions) +
    scale_colour_manual(values=c('white')) +
    expand_limits(positions) +
    ylim(0, 3)

So I have two questions:

  1. Why does geom_polygon not work properly when the axis limits are restrained?
  2. Is there a more elegant solution to color the outlines than the one showed here?

Below are the plot outputs. Many thanks in advance.

Did not work properly using geom_polygon
Works but is not very elegant

  • 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-03T19:10:47+00:00Added an answer on June 3, 2026 at 7:10 pm

    I believe you are correct as to why it doesn’t work. Restricting the x or y limits using xlim or ylim clips the data prior to plotting. This will end up omitting some vertices from your polygon, so some stuff won’t get plotted.

    This is why there’s coord_cartesian, which allows you to adjust the x and y limits without clipping the data. It will “zoom” into the correct region, rather than clipping and then plotting.

    So instead of ylim, try + coord_cartesian(ylim = c(0,3)).

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

Sidebar

Related Questions

I have a cross-tab report which similar to this Problem is when there are
I seem to have similar problem as this guy: Django newbie deployment question -
I have a similar problem to the one enumerated in this question , except
I have a similar problem as this question . I have multiple web services
I have a similar problem to this post . I need to display up
I notice this thread: Fastish Python/Jython IPC , and I have a similar problem,
Although I have read the similar questions, this problem seems to be the exact
I know there have been a lot of questions similar to my small problem.
I have a similar problem as a previously solved problem of mine, except this
I have a similar problem to a question over here with the following code:

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.