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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:42:42+00:00 2026-06-17T08:42:42+00:00

HI I am using ggmap and gg_point function to show the measured data in

  • 0

HI I am using ggmap and gg_point function to show the measured data in an estuary.

The code that I used is as follows:

    library(ggmap)
al1 <- get_map(location = c(lon = -87.525, lat = 30.35), zoom = 12, maptype = 'terrain')

lon<- c(-87.604474,-87.55)
lat<- c(30.362563,30.35)
label <- c("A","B")
df<-data.frame(lon,lat,label)

p <- ggmap(al1)+geom_point(data=df,aes(x=lon,y=lat,shape=label,label=label),size=3)
p <- p + xlab("Longitude")+ylab("Latitude")
p <- p +geom_text(aes(label=label, size=3,vjust=0))
p <- p + labs(title="Monitoring stations ")
p

ggsave("plot.pdf")

Here when I use geom_text then I get the following error, “Aesthetics must either be length one, or the same length as the dataProblems:label”.

I want to place the label next to the points in the plot. I would like to place both points and label and with some spacing so that it would be easier to read.

I looked at this post “ggplot legend issue w/ geom_point and geom_text” and tried to fix my code as you can see above but I don’t know why I am having this issue.

There is another post How can I persuade ggplot2 geom_text to label a specified date in a time series plot? which talks the similar questions. Am I getting different results because I am using ggmap also ?

Please help me to solve this problem. Thank you so much.

Jdbaba

  • 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-17T08:42:43+00:00Added an answer on June 17, 2026 at 8:42 am

    Your problem is that you haven’t specified the aesthetics in geom_text correctly:

    geom_text(data = df, aes(x = lon, y = lat, label = label), 
              size = 3, vjust = 0, hjust = -0.5)
    

    You didn’t tell geom_text to use the variables from the data frame df. If you don’t do this, all aesthetics are inherited from the main call. Finally, when setting aesthetics to a single value, you don’t do this inside of aes(), but outside.

    I monkeyed with the hjust setting to get the labels to be visible.

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

Sidebar

Related Questions

I have this js code where I am using the Mapstraction library to show
using jquery-ui-map here is my code $(document).ready(function() {$('#map_canvas').gmap({ 'center': new google.maps.LatLng(3.162456,21.09375), 'zoom': 2, 'streetViewControl':
Here is the code that I am using: if (!($fp = fsockopen('ssl://imap.gmail.com', '993', $errno,
The problem is that i can't load google maps using the following code. Map
code: google.load(earth, 1); function gemap_init() { google.earth.createInstance('gemap', initCB, failureCB); } function initCB(instance) { try
I am using Drupal 7 - Location, GMap module. I have a view that
I'm using the following code in a php file <script> var geocoder = new
I am using http://code.google.com/p/jquery-ui-map/ HTML: <div id=map_canvas style=width: 100%; height:400px; latitude=123456 longitude=123456>Loading Map</div> jQuery
I'm using GMap for the first time, but my maps won't show... I'm looking
I am using the code for testing: <script type=text/javascript> // When map page opens

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.