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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:51:01+00:00 2026-05-30T01:51:01+00:00

I believe this question is slightly different than similar ones asked on here before

  • 0

I believe this question is slightly different than similar ones asked on here before because of the use of scale_fill_brewer(. I’m working on a choropleth similar to this one https://gist.github.com/233134

That looks like this:

Chloropleth

and the legend like:

legend

I like it but want to change the labels on the legend from cut looking labels ie (2, 4] to something more friendly like ‘2% to 4%‘ or ‘2% – 4%‘. I’ve seen elsewhere it;s easy to change the labels inside of scale_… as seen here. I can’t seem to figure out where to put the labels= argument. I of course could re code choropleth$rate_d but that seems to be inefficient. Where should I put the argument labels=c(A, B, C, D...)?

Here’s the piece of the code of interest (for the full code use the link above)

choropleth$rate_d <- cut(choropleth$rate, breaks = c(seq(0, 10, by = 2), 35))

# Once you have the data in the right format, recreating the plot is straight
# forward.

ggplot(choropleth, aes(long, lat, group = group)) +
  geom_polygon(aes(fill = rate_d), colour = alpha("white", 1/2), size = 0.2) + 
  geom_polygon(data = state_df, colour = "white", fill = NA) +
  scale_fill_brewer(pal = "PuRd")

Thank you in advance for your assistance.

EDIT: USing DWin’s method (should have posted this error as this is what I ran up against before)

> ggplot(choropleth, aes(long, lat, group = group)) +
+   geom_polygon(aes(fill = rate_d), colour = alpha("white", 1/2), size = 0.2) + 
+   geom_polygon(data = state_df, colour = "white", fill = NA) +
+   scale_fill_brewer(pal = "PuRd", labels = lev4)
Error: Labels can only be specified in conjunction with breaks
  • 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-30T01:51:03+00:00Added an answer on May 30, 2026 at 1:51 am

    Besides adding a modified version of the levels, you also need to set the ‘breaks’ parameter to scale_fill_brewer:

    lev = levels(rate_d)  # used (2, 4] as test case
     lev2 <- gsub("\\,", "% to ", lev)
     lev3 <- gsub("\\]$", "%", lev2)
     lev3
    [1] "(2% to 4%"
    lev4 <- gsub("\\(|\\)", "", lev3)
     lev4
    [1] "2% to 4%"
    
    ggplot(choropleth, aes(long, lat, group = group)) +
      geom_polygon(aes(fill = rate_d), colour = alpha("white", 1/2), size = 0.2) + 
      geom_polygon(data = state_df, colour = "white", fill = NA) +
      scale_fill_brewer(pal = "PuRd", labels = lev4, , breaks=seq(0, 10, by = 2) )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I believe that this question has been asked in a few different forms, but
I believe this question has been asked before. I tried looking for it but
I believe this question might have been previously attempted in 2006 on a different
I believe this question applies equally well to C# as to Java, because both
This is driving me nuts. I believe I asked this exact same question, but
I believe this question has been asked a lot of times, and I have
I believe this question was asked several months back, but i believe my situation
I believe this question will be fairly easy for the ones who played around
i use a livegrid in ExtJs 3.3.1 but believe this question is global to
I believe this question applies to any of the For Html helpers, but my

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.