0

I want to plot specific coordinates on a map, and then label the points. I started to use R, I came across with rworldmap package. Is it possible to label any points, not the countries?

Data format;

Company Latitude    Longitude   Type
C1  20.0000 30.0000 C
S2  40.0000 50.0000 S

My code;

jdat <- read.table(file.choose(), header = TRUE)
colnames(jdat) <- c("comp", "lat", "lon", "type")

library(rworldmap)
newmap <- getMap(resolution = "low")
plot(newmap, xlim = c(10,60), ylim = c(10,60), asp = 1)

jcol <- c('red', 'blue', 'green')
type <- c("C", "S", "F")
dfa <- cbind.data.frame(jcol,type)
colnames(dfa) <- c("jcol", "type")
(jdatc <- merge(jdat, dfa))

points(jdatc$lon, jdatc$lat, col = jdatc$jcol, pch = 20, cex = 1.0)
text(x=jdatc$lon,y=jdatc$lat,labels=jdatc$comp)
legend(x='topleft',legend=as.character(dfa$type),col=dfa$jcol,pch = 20)

The code works, but only 'text' command gives the error below.

Warning message:
In xy.coords(x, y, recycle = TRUE, setLab = FALSE) :
  NAs arising from coercion (translation)

How can I label the points?

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
seeker
  • 61
  • 1
  • 11
  • @KonradRudolph Well, you edited the title, ok, but I had no answer with 21 views in 40 days, an average of 0,53 views/day. Here is another sample; stackoverflow.com/questions/56623413/… R and rworldmap are used in the title, 3,54 views/day. These words in the title may be a factor. What do you say about this? – seeker Jun 28 '20 at 03:28
  • That’s simply the rules: [tags don’t belong in the title](https://meta.stackexchange.com/a/130208/1968); instead, that’s literally what *tags* are for. And views are almost certainly unrelated, since Stack Overflow does not take this into account when sorting the questions, and Stack Overflow takes care to make questions appropriately searchable by third-party search engines. For instance, when googling for paraphrasings of your question title and “rworldmap”, your question shows up in the top hits. – Konrad Rudolph Jun 28 '20 at 10:16
  • @KonradRudolph I read the link you provided, I see that it is not a rule, it says 'unnecessary', also uses 'don't have to'. You can also check the comments part of that answer for a broader view. Actually, my current title without critical words is meaningless even to me, probably to any reader. There is also a contradiction unless you also remove the same words from the title of the link I gave in my first comment. Hope you do so. – seeker Jul 06 '20 at 07:50
  • The text is phrasing it politely. When it says “don’t have to” it means “should not”. There have been many discussions of this, and the consensus is clear. If you feel that your title is not descriptive enough (for the record: I completely disagree, even without considering the tags, which *form part of the question!*), then feel free to *make it more descriptive*. But in an organic way, i.e. write a sentence (fragment). Don’t just prepend or append a bunch of tags. – Konrad Rudolph Jul 06 '20 at 08:36
  • @KonradRudolph “don’t have to” does not mean “should not”. Anyway. To be consistent, could you remove the same words from the title of this link? (https://stackoverflow.com/questions/56623413/) – seeker Jul 07 '20 at 17:42
  • In the context of the linked discussion, yes, it does mean that, it’s an understatement. Trust me. Regulars **hate** tags in the title: they’re super annoying when browsing questions. And yes, this obviously also counts for the question you linked. And I’d edit it, too, if that would bump a year-old question back to the home page. – Konrad Rudolph Jul 07 '20 at 17:56
  • Anyway, I think this discussion doesn’t lead anywhere. Unfortunately have no experience with that package so I can’t help you. But you can drastically increase your changes of an answer by editing your question to include a minimal, reproducible example that somebody could execute. – Konrad Rudolph Jul 07 '20 at 17:58

0 Answers0