I have location data from 5 years (>30,000 points). Each location is given a classification name (in my case vegetation classes). These vegetation classes were assigned by intersecting the locations with vegetation maps representing 5 different years. The vegetation categories changed due to clear cut practices. Basically, some old forest areas in 2007 became clear cut in 2008, and others in 2009 became clear cuts in 2010 etc. Also, some old clear cuts became young forests because they grew back. What I want to know is, if I used just 1 map (say 2007) - how many wrong classifications will I have per year after this? Because what was once forest in 2007 could be clear cut in 2009. Knowing that the location from year 2009 is a clear cut, using the map from 2007 - was it misclassified? I will want to test this for each year. Basically, is there a map that minimizes miss-classification of points.

In the data set for each XY location, I have Year location was collected, clearcut07, clearcut08, clearcut09..., Names07, Names08, Names09....

The clearcut07 is binary indicator of 1 or 0, if was really a clear cut that year. the Names07 are the categorical names for all locations (all 5 years of points - if they were to be classified from that year). So, all locations obtained are given the attributes from the 2007 map, then the 2008 map then 2009, etc.

I need a summary of counts of locations within each category. A count of locations that were properly classified as clear cuts from each year of the data. A count of locations from data collected, for example, in 2008 that were classified as clear cuts from each map? And a count of locations that were incorrectly classified as clear cuts from each map when I know the correct classification.


1 Answer 1


it sounds like you want to display the map that corresponds to the year that is most reflective of the sample as a whole. To me, this sounds like you want to be able to show how forest vegetation changes over time in addition to providing some numerical summary of that. However if I interpret your question directly then it seems like you want to do a multiple regression that uses longitudinal data.

Assuming visualization and summary is the goal using R. I'm recommending changing your data around with sqldf and visualizing it with ggplot2.

If I've understood what you're trying to do then this is a two step process. Step 1 is data set revision. Step 2 is visualization.

The first step seems like you need to do a 'one-to-many' command to add information to your dataset that answers: "summary of counts of locations within each category", "count of locations that were classified as clear cuts from each year of the data, "locations classified as clear cuts from each map".

You want to do this in R so here's the script: [ggplot2 package has been acting up for the record]

Comparing yearly categorical data



Replicating location dataset

Roll= c("A","B","C","D","E","F", "G","H","I","J")

RollTide= function(n) sample(Roll[1:10],n,replace=T)


data <- data.frame(Year = sample(1:5, 100,replace=T), Location = c, 
    Clearcut = sample(0:1, 100, replace=T))

adding onto dataset

#per category
sum_count_loc<-sqldf("select *, sum(Clearcut)as TotLocal from data group by Location,Year") 
#per year
clear_cut_loc<-sqldf("select *, count(Clearcut)as CountLoc from data group by Location,Year")
#per map
clear_cut_map<-sqldf("select * from data group by Year, Clearcut,Location")

visualize data

df.m <- melt(data)

ggplot(df.m) + geom_freqpoly(aes(x = value, y = ..density.., colour = variable))

ggplot(df.m) + geom_density(aes(x = value, colour = variable)) + labs(x = NULL) + opts(legend.position = "none") + opts(title = "Forest Vegetation Over Time")


  • $\begingroup$ thank you for your answer, I will go try this. I appreciate your attempt to filter through what I needed. Its very hard for me to explain. $\endgroup$
    – Kerry
    Commented Sep 16, 2012 at 8:51
  • $\begingroup$ @Kerry The code I gave you for the step2 visualization part is buggy. The libraries you need to use are: "sqldf", "ggplot2", "reshape2". My idea was to visualize it using a heatmap. The problem is the way the data set "data" is constructed. I think if you use your original spreadsheet, idk what that is exactly, it should work. B/C there are separate columns for clearcut. ex. Clearcut08. If you give me more information I can help you more. $\endgroup$
    – Tyler
    Commented Sep 16, 2012 at 18:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.