Thursday, March 28, 2013

Generate GIS integrated animation:Gun deaths animation - R

# I wanted to briefly revisit a previous post in order to update the graphics.



# The code used in the previous post has also become more useful since the database of guns deaths has tripled since the original post (yay!).

# If you would like to generate your own graph, make sure to use the r code attached to the original post rather than the original post.


# We can see a steady decline in gun deaths.  I am not sure what is driving this exactly.  I suspect maybe a decrease in gun suicides due to the winter coming to an end is driving this though I think gun deaths will rise as murders start increasing during the summer months.

2 comments:

  1. Hey Francis. I really liked your post. I have always wondered if it was possible to produce animated graphs in R, and now I see there is a way.

    I just wanted to comment on your use of for-loops when generating the cumulative sum. There is already an R function that does this called cumsum. You could implement it by replacing :

    for (i in 1:ndays) gun.deaths$day[gun.deaths$dates==names(deaths.tab)[i]] = i

    with this:

    cum.deaths <- cumsum(deaths.tab)

    This would definitely simplify the look of your code, as well as the execution since you wouldn't be using as many for-loops.

    Just thought I would throw that out there.

    Thanks again for the post!

    ReplyDelete
    Replies
    1. Thanks Jonathan,

      Honestly, I still feel very new to R and all tips and suggestions help.

      Francis

      Delete