0

I am using R to create a surface chart out of data from a csv file with the following schema:

Date,Event Score,Location
2014-01-01,10,Louisville
2014-02-03,13,Atlanta
2014-03-10,99,Boulder

Just to clearly, that is to say, in Louisville there was an event score of 10 on January 1st, 2014; February 2nd, 2014 in Atlanta saw an event score of 13; and finally in Boulder on March 10th, 2014, there was an event score of 99.

I have about 100,000+ records like this and would like to generate a surface chart with x axis being the city name, the y axis being the date, and the z axis simply being normal numerical data (the "event score").

I pull in the data using the following via this site:
HM <- read.csv("/path/to/data.csv")

And convert the date column as follows via this post:
HM$Date <- as.Date(HM$Date, "$Y-%m-%d")

I have attempted a couple times with wireframe from lattice, but to no avail. I have a feeling it is related to my understanding of how R manipulates data in variables. I even tried just mapping the date and the score using R_Users technique, alas again with no results. Below is how I mocked up his code:
HM <- read.csv("/path/to/data.csv")
HM$Date <- as.Date(HM$Date, "$Y-%m-%d")
plot(Event.Score ~ Date, HM, xaxt = "n",type = "1")
axis(1, HM$Date, format(HM$Date, "%b %d"), cex.axis = .7)

After running the plot command, I receive the following error:
Error in plot.window(...) : need finite 'xlim' values
In addition: Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf

What I am looking for is either a direction to some clearer documentation on how to chart an axis as a list of names/dates and any advice, tricks, or examples of how to actually generate this.

Thank you much, and feel free to follow up with questions.

Community
  • 1
  • 1
YayDK
  • 121
  • 4
  • 1
    For `lattice`, try `levelplot(Score ~ Date + Location, HM)` – agstudy Mar 07 '14 at 18:26
  • Terribly useful. Thank you! This is definitely a start. I've done both wireframe/levelplot(Score ~ Date + Location, HM). The graphics are not quite what I'm looking for, but you have definitely pointed me in right direction. Thank you again so much! – YayDK Mar 07 '14 at 19:35

1 Answers1

0

Just to follow up, in case anyone stumbles onto this, to get this working I had to normalize my original data.

That is to say, I had to convert the data to not just have entries where the days had events. R cannot interpret nil data. So a day with no events had to manually have a score of 0 inputted. In other words, I had to convert this data set:

Date,Event Score,Location
2014-01-01,10,Louisville
2014-02-03,13,Atlanta
2014-03-10,99,Boulder

To something like this:

Date,Event Score,Location
2014-01-01,10,Louisville
2014-01-01,0,Atlanta
2014-01-01,0,Boulder
2014-01-02,0,Louisville
2014-01-02,0,Atlanta
2014-01-02,0,Boulder
2014-01-03,0,Louisville
2014-01-03,0,Atlanta
2014-01-03,0,Boulder
...
2014-03-10,0,Louisville
2014-03-10,0,Atlanta
2014-03-10,99,Boulder

Once my data was formatted in this manner, the following worked flawlessly:

HM <- read.csv("/path/to/data.csv")
wireframe(Event.Score ~ Date + Location, HM)

Additionally, unlike with levelplot, wireframe does not seem to like interpreting Dates with the as.Date function. Leaving it as is was much easier that trying to convert it into a date range, unlike with levelplot.

YayDK
  • 121
  • 4