Automating great-circle map production in R

若如初见. 提交于 2019-12-04 04:40:37

Too much information for a comment, so I post an answer instead. Here is what I think (and read to the end to see what could potentially be the problem):

I have tried to run your code on the original data in the Flowing Data tutorial. (Obviously you have to add a column for monthly data, so I simply added this line to randomise the month:):

airports <- read.csv("http://datasets.flowingdata.com/tuts/maparcs/airports.csv",
                     header=TRUE) 
flights <- read.csv("http://datasets.flowingdata.com/tuts/maparcs/flights.csv", 
                    header=TRUE, as.is=TRUE)

# Add column with random data for month
flights$month <- sample(month.abb[1:4], nrow(flights), replace=TRUE)

Whenever I have a loop that takes a long time to run, I generally stick a bit of code in there that gives me a progress check. Use what takes your fancy: print, cat, tcltk::tkProgressBar. I use message:

for (i in 1:length(monthyear)) {
  message(i)
  #
  # your code here
  #
}

Anyway, I then ran your code. Everything works exactly as it should. Since I sampled four months worth of data, I get:

  • The message with the current iteration of i prints four times
  • Four png plots, each with a dark world map and bright yellow lines. Here is one of the four lines:


So, why does it work on my machine and not yours?

I can only guess, but my guess is that you haven't set the working directory. There is no setwd in your code, and the call to png just gives the filename. I suspect your code is being written to whatever your working directory is in your system.

By default, on my installation, the working directory is:

getwd()
[1] "C:/Program Files/eclipse 3.7"

To solve this, do one of the following:

  1. Use setwd() to set your working directory at the top of your script.
  2. Or use the full path and file name in your call to png()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!