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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:31:21+00:00 2026-05-25T17:31:21+00:00

My objective is to plot the path of a river with points indicating important

  • 0

My objective is to plot the path of a river with points indicating important sites near the river.

I have two data frames, giving the river and site coordinates respectively:

river<-data.frame(
    long=c(-2.816452494909265,-2.845487331898639,-2.883036393822358),
    lat=c(56.38229290416972,56.36346886284386,56.36577994637793))

samploc<-data.frame(
    site=c("Site1","Site2","Site3"),
    long=c(-2.826213585663894,-2.816519300644918,-2.868437228090127),
    lat=c(56.3649482229089,56.38166100310631,56.36716019476281))

Using an old school R plot, with par(new=T) and conserving xlim and ylim, I would get something like this:

old school plot http://users.utu.fi/susjoh/Riverplot.png

But I would like to do it using ggplot2. The river and points can be easily called individually:

ggplot(river,aes(x=long,y=lat)) + geom_path()
ggplot(samploc,aes(x=long,y=lat,lab=site)) + geom_point() + geom_text(vjust=2)

I have tried to cheat, by creating the following data frame from the previous two:

> rivsamp
  river.long river.lat samp.site samp.long samp.lat
1  -2.816452  56.38229      NA        NA       NA
2  -2.845487  56.36347      NA        NA       NA
3  -2.883036  56.36578      NA        NA       NA
4         NA        NA     Site1 -2.826214 56.36495
5         NA        NA     Site2 -2.816519 56.38166
6         NA        NA     Site3 -2.868437 56.36716

ggplot(rivsamp) +
  geom_path(aes(x=river.long,y=river.lat)) +
  geom_point(aes(x=samp.long,y=samp.lat)) +
  geom_text(aes(x=samp.long,y=samp.lat,lab=samp.site),vjust=2)

ggplot2 plot http://users.utu.fi/susjoh/riverggplot.png

It works, but creating this new data frame is not as straightforward as the old par(new=T) method.

Is there a simpler way to overplot from the individual data frames using ggplot2?

Thanks!

  • 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-25T17:31:22+00:00Added an answer on May 25, 2026 at 5:31 pm

    Here is one way to do it

    ggplot(samploc, aes(x = long, y = lat)) + 
      geom_point() + 
      geom_text(aes(label = site), vjust = 2) + 
      geom_line(data = river, aes(y = lat))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Objective: In support of a Windows Service that may have multiple instances on a
Objective Have a small magnifying glass icon that appears in the top right corner
In Objective-C I have a timer fire every 0.1 seconds and increment a double value
Objective-C doesn't have namespaces, and many (such as CocoaDevCentral's Cocoa Style Guide ) recommend
Objective: I have a list of header files (about 50 of them), And each
Objective I have a main DIV with fixed height and width, and in that
Objective C - iPhone Application I have 2 programatically instantiated UINavigationControllers In controller 1
my only objective is to create a scatter plot with only x and y
Objective-C is really wierd, i can't get the hang of it... I have a
Objective c | xcode | iphone question Im building a model(data) class for a

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.