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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:06:45+00:00 2026-06-05T19:06:45+00:00

FYI: I’m fairly new to ggplot2 and ggmap so I apologize for the sloppy

  • 0

FYI: I’m fairly new to ggplot2 and ggmap so I apologize for the sloppy code but it is the only way I’ve been able to plot sets of groups of points where each group has it’s own color. Also my os is ubuntu.

I’m trying to add a legend, to a ggmap object and in particular a legend with a continuos gradient transitioning the colors. Any advice? I’ve tried the legend attribute in ggmap but it doesn’t seem to be working. Below is what I have so far.

syd = get_map(location = center, zoom = zoom, maptype = type,color = "bw")

(SYDmap = ggmap(syd, extent = "panel",legend="right")+ annotate('point',x=lng[[1]],xend=max(lng[[1]]),y=lat[[1]],yend=max(lat[[1]]),colour=colorval[1],cex=cexval,pch=pchval))

for(i in 2:(topnum - 1))
  SYDmap<- SYDmap + annotate('point',x=lng[[i]],xend=max(lng[[i]]),y=lat[[i]],yend=max(lat[[i]]),colour=colorval[i],cex=cexval,pch=pchval)

i=topnum;  (SYDmap <-   SYDmap + annotate('point',x=lng[[i]],xend=max(lng[[i]]),y=lat[[i]],yend=max(lat[[i]]),colour=colorval[i],cex=cexval,pch=pchval)) + guides(fill = "colourbar")
  • 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-05T19:06:46+00:00Added an answer on June 5, 2026 at 7:06 pm

    Instead of using annotate, here’s a method that adds a point layer using geom_point. Almost any geom can be added to a ggmap object as it would be added to a ggplot object. Because Size (see the contents of the df data frame below) is a colour aesthetic in the call to geom_point, the legend is generated automatically.

    library(ggmap)
    
    # Get a map - A map of Canberra will do
    ACTmap = get_map(c(149.1, -35.325), zoom = 12, source = "google", maptype = "roadmap")
    
    # A data frame of lon and lat coordinates and the variable Size
    df = data.frame(lon = c(149.0307, 149.1326, 149.089, 149.048, 149.0965),
                lat = c(-35.3892, -35.28225, -35.34005, -35.34857, -35.34833),
                Size = c(1,2,3,4,5))
    
    # Draw the map
    ACTmap = ggmap(ACTmap)
    
    # Add the points
    ACTmap = ACTmap + geom_point(data = df, aes(x = lon, y = lat, colour = Size), 
          alpha = 0.6,  size = 10)
    
    # Change the legend
    ACTmap + scale_colour_continuous(low = "red", high = "blue", space = "Lab", guide = "colorbar")
    

    enter image description here

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

Sidebar

Related Questions

FYI I'm programming in objective-C but anyone might be able to help. I've been
Ok, so I have the code below (Objective-C FYI) and I was wondering if
This code trims whitespace, (fyi: it's credited to be very fast) function wSpaceTrim(s){ var
This should be fairly simple; i'm pretty sure I've just not understood it. FYI,
FYI: I have edited this significantly since my first edition. This simulation has been
This question is based on a previous , but that's just FYI. I've managed
*As a first note, I only have read access to my server. Just, FYI
Edit: FYI for future readers, this issue has been fixed as of version 2.3.606.0
Just fyi, I am new to WPF. I am creating a sidebar in my
Rookie question FYI. Whenever I compile/run the code, extern tolayer2(rtpktTo1); I receive a warning.

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.