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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:08:10+00:00 2026-05-22T03:08:10+00:00

I’m creating a map using the maps library and ggplot’s geom_polygon. I’d simply like

  • 0

I’m creating a map using the maps library and ggplot’s geom_polygon. I’d simply like to change the default blue, red, purple colour scheme to something else. I’m extremely new to ggplot so please forgive if I’m just not using the right data types. Here’s what the data I’m using looks like:

> head(m)
region      long      lat group order subregion Group.1 debt.to.income.ratio.mean    ratio total
17 alabama -87.46201 30.38968     1     1      <NA> alabama                   12.4059   20.51282    39
18 alabama -87.48493 30.37249     1     2      <NA> alabama                   12.4059 20.51282    39
19 alabama -87.52503 30.37249     1     3      <NA> alabama                   12.4059 20.51282    39
20 alabama -87.53076 30.33239     1     4      <NA> alabama                   12.4059 20.51282    39
21 alabama -87.57087 30.32665     1     5      <NA> alabama                   12.4059 20.51282    39
22 alabama -87.58806 30.32665     1     6      <NA> alabama                   12.4059 20.51282    39

> head(v)
          Group.1 debt.to.income.ratio.mean    ratio     region total
alabama       alabama                  12.40590 20.51282    alabama    39
alaska         alaska                  11.05333 33.33333     alaska     6
arizona       arizona                  11.62867 25.55556    arizona    90
arkansas     arkansas                  11.90300  5.00000   arkansas    20
california california                  11.00183 32.59587 california   678
colorado     colorado                  11.55424 30.43478   colorado    92

Here’s the code:

library(ggplot2)
library(maps)

states <- map_data("state")
m <- merge(states, v, by="region")
m <- m[order(m$order),]

p<-qplot(long, lat, data=m, group=group, fill=ratio, geom="polygon")

I’ve tried the below and more:

cols <- c("8" = "red","4" = "blue","6" = "darkgreen", "10" = "orange") 
p + scale_colour_manual(values = cols)
p + scale_colour_brewer(palette="Set1")
p + scale_color_manual(values=c("#CC6666", "#9999CC"))
  • 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-22T03:08:11+00:00Added an answer on May 22, 2026 at 3:08 am

    The problem is that you are using a color scale but are using the fill aesthetic in the plot. You can use scale_fill_gradient() for two colors and scale_fill_gradient2() for three colors:

    p + scale_fill_gradient(low = "pink", high = "green") #UGLY COLORS!!!
    

    I was getting issues with scale_fill_brewer() complaining about a continuous variable supplied when a discrete variable was expected. One easy fix is to create discrete bins with cut() and then use that as the fill aesthetic:

    m$breaks <- cut(m$ratio, 5) #Change to number of bins you want
    
    p <- qplot(long, lat, data = m, group = group, fill = breaks, geom = "polygon")
    p + scale_fill_brewer(palette = "Blues")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I've got a string that has curly quotes in it. I'd like to replace
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

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.