Rex Cao
Rex Cao

Reputation: 3

R studio - lwd argument does not work in lines() function

I recently studied how to draw flight route between two destinations.

I learned the code from here https://www.gis-blog.com/flight-connection-map-with-r/?unapproved=5101&moderation-hash=f14c3f9e10eb5d9e983e2339bdcf05c2#comment-5101

In the blog, the map looks like this. As you can see the lines in the sample picture in very thin and transparent.

I did exactly what it asked me to do and but when I plot the map it looks like that. As you can see lines in the map I generated is very thick

Even i tried to change the lwd value, i did not find any difference, i am confused on why this happened. Any one has any clue on this?

This is my code:

for (i in (1:dim(usairports)[1])) { 
  inter <- gcIntermediate(c(jfk$lon[1], jfk$lat[1]), c(usairports$lon[i], usairports$lat[i]), n=200)
  lines(inter, lwd=0.000001, col="turquoise2")    

Thanks in advance

Upvotes: 0

Views: 225

Answers (1)

Marius
Marius

Reputation: 60180

R on Windows has notoriously bad aliasing by default in its plots, meaning you see very "jagged" lines. Using the Cairo plotting system tends to give much better results, e.g.:

png("airport.png", type = "cairo")

map("world", regions=c("usa"), fill=T, col="grey8", bg="grey15", ylim=c(21.0,50.0), xlim=c(-130.0,-65.0))
#overlay airports
points(usairports$lon,usairports$lat, pch=3, cex=0.1, col="chocolate1")

for (i in (1:dim(usairports)[1])) { 
    inter <- gcIntermediate(c(jfk$lon[1], jfk$lat[1]), c(usairports$lon[i], usairports$lat[i]), n=200)
    lines(inter, lwd=0.1, col="turquoise2")    
}

dev.off()

Upvotes: 2

Related Questions