An Easy Way to Map Data in R with Plotly

A couple of years ago, I wrote The complete n00bs guide to mapping in R, my first adventure into R. While that tutorial still holds up, if you’re looking to make a state-level Choropleth Map, there really isn’t anything easier than working with Ploty in R.

Once you get R and RStudio installed and set up, there’s only a few steps that you need to take. If you have a spreadsheet or can make one easily enough of state-level data, like this ranking of mental health and access in the USA by states , you only need a couple of lines of code (minus all the comments that follow the #s).

Let’s start by getting plotly set up.
install.packages("plotly") #installs the Plotly library for R
library("plotly") #tells R you want to use the Plotly library package

I just made a CSV file by copying the information from the website. One column was “state” and the other was “rank.” Because the data was which state and its rankings it was simple. Warning: In this case, the states do need to be copied as postal abbreviations for this to work. Plotly can also do countries. Check out their documentation for the changes you’ll need to make.

Import your spreadsheet and give it a name to use in R
mh<- read.csv("C:\\Users\\Documents\\mentalhealth.csv", header = TRUE, sep = ",")

And we're ready to plot it!
plot_ly(type="choropleth", locations=mh$state, locationmode="USA-states", z=mh$rank) %>% layout(geo=list(scope="usa"), )

Boom!
And did I mention it's interactive!

A map of the US with the states shaded in colors ranging from dark blue to yellow
Click for a full size map

Another Example
Because plotly makes the mapping so simple, I finally got around to looking at the geographic distribution of the All-America City Award. It started in 1949 and the city I grew up in (Grand Rapids, MI) was one of the inaugural winners in 1949. Since finding out about the award, I was curious if there was any states that did particularly well. However, it was one of those curiosities that was never really worth the effort. Until Plotly made it super easy!

I copied the table straight from Wikipedia and stripped it down to the just the state column. A few metropolitan areas are listed with multiple state winners so split the entry giving both states their own line in the data. I also deleted Puerto Rico (sorry Puerto Rico). I then brought it the file as above.
usacities<- read.csv("C:\\Users\\Documents\\allamericanwins.csv", header = TRUE, sep = ",")

This time, I took a few extra steps. Because my data was just a list of states over and over again (Alabama, Alabama, Wisconsin, North Carolina, Wisconsin, etc), I needed to count how many times each state was in the file. R makes it easy to generate a frequency table.
table(usacities)
(I told you it was easy)

I then made a new file out of the frequency table because that's how I roll.
write.csv(table(usacities), file = "C:\\Users\\Documents\\allamericanwinsfreq.csv")

I changed the state names to postal abbreviations and add NV and UT who had zero wins, then I was ready to bring in the file and plot the map.
usa<- read.csv("C:\\Users\\Documents\\allamericanwins1.csv", header = TRUE, sep = ",") plot_ly(type="choropleth", locations=usa$state, locationmode="USA-states", z=usa$wins) %>% layout(geo=list(scope="usa"), )
I suppose I could have done this at the beginning and skipped the whole writing a new document thing but hey that's hindsight for you.

A map of the US with states shaded from dark red to light grey
Click for a full size map

It looks like the upper Midwest and and North Carolina/Virginia are the big winners of the award. Because I wanted to get an idea of how this fit with the state's populations, I did some more simple calculations (finding the difference in each state's ranking of number of times they won the award and the rank in total population. This map shows Alaska as a big winner. The Great Plains stays as a winner and this time the South is shown to be a loser when it comes to this award. New England did ok too.

A map of the US with states shaded in colors ranging from blue to red
Click for a full size map



Now go forth and create choropleth maps!

What makes your city famous?

Last weekend, I was watching Clueless and looked up Pismo Beach, California on Wikipedia after Cher spearheads the disaster relief efforts for that city. I was pleasantly surprised to find that Pismo Beach claims to be the “Clam Capital of the World.” My dissertation examines the identities of cities claiming to be the “Capital of the World” in various industries during the Gilded Age and Progressive Era and I recently released a digital project examining how Grand Rapids took on the identity of “Furniture City”. City identities, particularly ones based on economics, have been an interest of mine for a while now and often produce lovably quirky nicknames and slogans.

Wondering what other cities and towns integrate specific products into their urban identity, I am launching a project where I ask What Makes Your City Famous? I have created a simple form that asks for the City, Zip Code, City Nickname or Slogan and Source (where I can verify the information). Once the information is collected, I use Google Fusion Tables to create an interactive map that displays the cities and their nicknames. I chose Google Fusion Tables because of the ease in transitioning from a Google Form to Map and used zip codes to help cities display multiple nicknames. I populated the map with a few cities to start, but hope that this project will draw on user knowledge from across the country to uncover a variety of local identities.

So please, tell me What Makes Your City Famous?

“The Biggest City of Its Size in this Country”

At the beginning of the semester, I finished my dissertation prospectus. My committee told me to drastically cut the number of case studies with which I had begun (among many other good suggestions), lightening the workload while keeping the core idea. With the semester over, I’m going to try to recommit to discussing my research as it is in progress, particularly because I’m embarking on a new digital project, but I’ll blog more about that in the near future. The following is a rather long-winded personal account of how I got to my dissertation topic, if you want my succinct pitch, see the tl;dr version at the bottom of the page.

As an academic topic, the core idea of my dissertation comes out of my MA thesis, but it also has much earlier, more personal roots. Growing up in Grand Rapids, I enjoyed going to the city’s public museum. The museum is quite nice, with many awe-inspiring exhibits, including a blue whale skeleton hanging over the main lobby, a planetarium, and replication of an old city street. Walking through the fake brick street was a favorite activity of mine, if you were lucky there would be a reenactor staffing one of the businesses. Watching the giant printing press was fun—and resulted in free handouts! The pharmacy with the soda fountain was the business to catch, even if it didn’t actually serve ice cream floats. Most of the time we ended up pressing our noses up on the glass doors hoping an employee was hiding somewhere inside. At the end of the road, there was a small train depot with time tables. I always sat down and wondered if there would ever be anyone appearing behind the ticket counter, though this was about as likely as a train actually pull up as there was no door to get behind the window.

To cut to the chase, even as a child, I was a bit of a history nerd. You would think, then, that the permanent exhibit on the city’s furniture history would be more of a highlight to me. A rather impressive space, complete with motion detecting animatronic people. Though we mostly just enjoyed triggering the censors and collecting, not necessarily reading, the baseball card style descriptions of different city characters. A well designed exhibit, but no match for the rowdiness of young boys. Regardless of my disinterest in why my home touted itself as the “Furniture City,” the city’s past industrial importance was always present.

Faced with the opportunity to choose my first major research project as an undergraduate history major writing an honor’s thesis, I gravitated towards my hometown once again. A typographical strike in the 1950s caught my eye, though very little sources survived. In researching the topic, though, I stumbled upon a fascinating strike in St. Louis at about the same time, which soon became my topic.

When faced with a MA thesis topic, I tried to stay away from looking at Grand Rapids, but eventually, with no promising topics and the pressing need to start working on something, a bit reluctantly I returned to hometown history. The topic, a political scandal emerging out of bids to build a find a new urban water supply, first caught the eye of my dad, a lawyer in Grand Rapids. Years before he had stumbled upon lawsuits relating to a citywide scandal. He had tucked these cases away, but never did anything until he passed them on to me when I was an undergraduate. I figured there was enough materials for a thesis, and I was certainly correct. As I dug into the story it became increasingly interesting and complex. My MA thesis explored the way in which social, economic, political, and even spatial relationships affected Progressive-style reform and it lead me to perhaps the defining focus of my dissertation: cities outside the metropolis function differently because of their size. Small cities are caught between small town and big city lifestyles and this betweenness is something of which the residents are quiet aware. Grand Rapids boosters often touted a quote credited to James Blaine, describing he city as “the biggest city of its size in this country” (This phrase may ring a bell as Reno, Nevada’s status as “the biggest little city in the world” draws on the same idea). While historians have told the story of industrialization and urbanization in the metropolis and the small town rather extensively, the way in which these processes developed in small cities needs more scholarly investigation. Small cities became my scholarly focus moving forward.

I didn’t want to just expand on my MA thesis. While Progressive reform plays a part in the larger story my dissertation will tell, it alone was not enough to capture my interest. Instead, I returned to my hometown’s ever present identity as the “Furniture City.” I quickly found many cities in the Midwest and Northeast claimed similar titles, whether they were rightfully earned or not. I unearthed “furniture cities,” “silver cities,” and even East Liverpool, OH and Trenton, NJ which both laid claimed to the title of the “Staffordshire of America” (which among other things, tips off the domestic industry’s inferiority complex). These strong urban identities, not as metropolis, but king of one industry, began driving my research.

In my working title, “The Rise and Fall of the American Small City: Industrialization and Urbanization in Cities Outside the Metropolis, 1870-1930,” I invoke a rise and fall narrative. In general these cities have similar narratives resembling this framework. Founded earlier in the Nineteenth century (or even earlier), they do not experience rapid growth until after the Civil War. Their importance on the national stage piques during this time as they become significant players within niche industries. These niche industries end up shaping the urban experiences in many significant ways, including building specialized immigration networks, retaining a focus on craftsmanship, and creating a powerful city elite (though one still very much tied to the old middle class). The Great Depression, continued industrialization in other regions, and other factors diminish the importance of these small cities within even their niche industries as the new century progressed. Grand Rapids shifted from finely crafted parlor and bedroom furniture to office furniture, auto parts, and even Amway. However, in many ways, the city’s leaders have revived the niche industry strategy, lately pushing Grand Rapids to become a major player in the craft beer industry. Once again suggesting that small cities navigate larger economic structures differently from other urban regions.

tl;dr version:
My dissertation examines a group of small cities during the Gilded Age and Progressive Era that specialized in a niche industry, gaining wider recognition and market share (Furniture: Grand Rapids, MI; Rockford, IL; Pottery: East Liverpool, OH; Silverware: Taunton, MA). With these cities, I argue that smaller cities, caught between rural town and metropolis, experienced the changes brought by industrialization and urbanization in a significantly different way. I hope that this alternative model of urban and economic change may provide insight for smaller cities as they grapple with current changes such as globalization.

Playing with Gephi

I finally got around to playing with sample data I collected on a research trip last summer. The data comes from the Rockford Chair and Furniture Company Records at Northern Illinois University. The most exciting part of this is that these visualizations were orders from one day, November 5, 1891, and they have several years of this data so there is much more potential in these records. I found Gephi quite easy to use and I’d recommend taking a look at it if you’re interested in making your own.

Orders by city
Orders by city
Orders organized by which railroad they were shipped
Orders organized by which railroad they were shipped
Orders georeferenced
Orders georeferenced
For those geographically challenged
For those geographically challenged

P.S. There’s a typo on two of the images, just pretend I know how to spelled “furniture” correctly.

Home of the Reuben

Later this month, Frank’s Kraut will officially name Omaha “The Home of the Reuben Sandwich.” While this title may seem like a humorous footnote in the city’s story, I would suggest it is indicative of the changing nature of Midwestern cities’ identities.

Omaha’s first identity was as one of the Gateways to the West. The city’s nicknames changed as Omaha’s position in the national economy shifted from gateway to a regional industrial center, earning titles such as “Porkopolis” and “The Magic City” (because the city’s seemingly instant growth was magical). However, Omaha’s magical period has ended. Though Omaha’s future may not depend on its position as “Home of the Reuben,” it certainly reflects the reality of the city’s changing economy. A national culture that renders many cities’ local experiences similar leaves urban areas looking for the things that maintain some individuality and might even bring in visitors. Just like Omaha, my hometown of Grand Rapids begun to change its identity in the past few years. Though once the Furniture City, Grand Rapids emphasizes other aspects of West Michigan life as furniture production waned, including its new (shared) position as Beer City USA.

Now it is possible that these slogans stand out because I’m just in the mood for a good beer and sandwich. However, I think there is a distinct shift towards cities appealing to identities less in the past manufacturing golden ages, which even have become baggage for cities within the Rust Belt. For example, Pittsburgh still has the Steelers, but the city no longer leans on its industrial heritage. The banner on the city’s webpage touts Pittsburgh as “A most liveable city.” The front page of the 2012 visitors guide highlights the city’s history as “The Birthplace of Pop Culture” and “Home of Art & Innovation, Celebrity, Entrepreneurial Spirit and The Andy Warhol Museum.” Just as Pittsburgh transitioned from one of the cities claiming to be the Gateway to the West to the Steel City (or rather, one of the Steel Cities), it is now changing its image to better fit the post-industrial economy of innovation and start-ups.

Omaha may not be planning on constructing an elaborate Reuben-centered city identity, but its efforts to highlight the city’s individuality do reflect other cities’ attempts to reinvent themselves in the new global economy.

Does size matter?

How big exactly is a small city? This came up at my panel at the Urban History Conference (and rightfully so, it was organized around the theme of small cities). Being a notion central to my research, I have thought a bit about what exactly it means, making some notes about what other sources have to say. NPR looked for art in “small to mid-sized cities” which it described as cities with under 50,000 people. I make the case that Grand Rapids is a small to mid-sized city, though its population is much larger (190,000 in the city and 750,000 in the metropolitan area). However, from my discussion with and readings of other scholars who study small cities, it seems pretty clear that the “smallness” of cities is not about size.

Instead, the city’s economic and social positioning is what really matters as to whether or not a city is “small” or “big.” So while Grand Rapids is the regional center of Western Michigan (it’s size and regional importance are making me think I should start using the term “mid,” but for consistency’s sake, I’ll stay with calling it and others “small” cities) it is very much in the shadow of Detroit and Chicago.

A quick way to find out whether your city is small or big is to look at its amenities. Does it have a professional sports team? Then it’s probably a big city. What about a major airport? I think you can make a good case. While I can continue to name non-scientific measuring sticks, I will look at a few commonalities of the nature of small cities to bring out the essence of a small city.

Fills an economic niche
Lacking the size to boast a robust, autonomous economy of its own, small cities specialize in one or a few closely related industries in order to gain national and even international importance. While on the most part small cities sit on a secondary or tertiary level of the national economy, these particular industries can allow the city to move up to a limited, but significant, place in the national marketplace.

Examples
Grand Rapids is the “Furniture City.”
Battle Creek is the “Cereal City.”
Akron is the “Rubber Capital of the World.”
Parks and Rec’s Pawnee, Indiana is even home to Sweetums.

Small and powerful elite
Often the family or families running a small city’s primary industry amass a large fortune. This vast amount of wealth that comes from controlling these national companies in small (and less expensive) cities grants them a huge amount of power over local affairs as major employers and city benefactors.

Examples
Grand Rapids’ early twentieth century had several important families, many heading furniture companies, though the better example comes from the contemporary city with Amway’s DeVos and Van Andel families. In Battle Creek, there was the Kellogg family and in Akron the Firestone, Goodrich, and other rubber elites. For Parks and Rec, it’s the Newport family.

Large (sometimes unusual) events designed to attract attention
Big cities don’t necessarily need large events to promote tourism and their local economy. These cities can rely on its attractive nature to turn ordinary events into large ones (such as the popularity of the New York, Chicago, or Boston marathons). Some cities themselves even become tourist attractions. A city like New York can have tourist buses drive around the city everyday. Grand Rapids, not so much. Instead, small cities take a strategy similar to their economic specialization. Small cities pick one event and make it big.

Examples
ArtPrize
The Fourth of July City
The World’s Largest Porch swing
Carhenge
The Harvest Festival
Ice Town

Where am I from?

Where are you from?

A simple question, well sort of. Even though it is a seemingly innocuous question, asking where some one “comes from” actually looks to discover the initial impressions of a person by situating them culturally as well as geographically. There are plenty of social stereotypes centered around geographical location. Like it or not, identifying as someone from a small rural city will give a different impression as someone from a large urban city. This does not mean that one is “better” but that a set of assumptions (correct or not) will be made about a person depending on where s/he identifies as her/his place of origin. What place we select as our geographic identity, in my experience at least, says more about our individual identity and current location than whichever place I was “from.”

I’m from Wisconsin

I was born in Madison, Wisconsin. It’s a lovely place, or at least that’s what I hear. I was only two when we left so I have no memories of the city. Despite the fact I can’t remember my birthplace, as a kid in Grand Rapids, Michigan, I enjoyed self-identifying as a Cheesehead. Though I suppose I was technically a Michigan football fan growing up (I know, what was I thinking), I took special interest in cheering for Ron Dayne and the Badgers from my first city.

I enjoyed the novelty of being from another state without having to be the new kid. Like most of my classmates, all my memories were of Western Michigan. I did not have to adjust to living in a new city, because I did not remember the old one. But, if I wanted, I could still claim to be foreign. In grade school, Madison could be my exotic birthplace.

I’m from Michigan

Wisconsin still holds a special place in my heart as my birthstate, but as I grew up I realized that millions of people are from Wisconsin. It’s not as unique as it seemed when I was a child. So my Michigan experiences became much more important to my self-identity.

My Michigan-ness really set in when I went off to college. Going to Notre Dame, I was suddenly in contact with people from states all across the nation. States that didn’t point to their hand when explaining where they came from (Grand Rapids is in the middle of the palm below the far side of the pinky). I met people actually “from” Wisconsin. So it was then that I very consciously and consistently became from Michigan, specifically Western Michigan. I met a fair amount of people either from Michigan or very familiar with the state so differentiating myself as being from the West side set me off from all those students from Detroit, well suburban Detroit.

A quick aside–Being from a city vs a suburban area often seemed to be a point of contention between students from Chicagoland. I once witnessed an argument about whether someone living in an Indiana suburb of Chicago could claim to be from the city, despite living in another state. Further complicating the debate, the Hoosier Chicagoan lived closer to the actual city of Chicago than the Illinois suburban student.

As I moved further from the city, where I was “from” became, without a doubt, Grand Rapids, Michigan. Even though I spent most of my time in South Bend, Indiana. Of course if I had identified as from South Bend, I would have been identified as a “townie.” And I was certainly not one of those.

I’m from Nebraska?

While I was clearly in South Bend temporarily, my move to Nebraska was more permanent. Assuming I stay living in Lincoln for the length of my Ph.D., Lincoln will be the city in which I’ll have lived for the longest after Grand Rapids. Also by then, I will be nearly a decade removed from Michigan being my year-round residence. So where was, or rather “am,” I from? When I travel I literally come from Nebraska. I have a Nebraska drivers license and have had for almost my entire time living in the state. I consider myself a resident, but does Nebraska feel the same way? I was just reading an article on UNL’s new athletic director, who the University Chancellor Harvey Perlman noted is “not a born Nebraskan, but he seemed like a Nebraskan when you sit down and talk to him.” So I wonder. Am I a Nebraskan, or do I just seem like one?

Lincoln is my home, though I can’t say it’s my hometown. When answering where I am from, after noting that I live in Lincoln I often mention that I grew up in Michigan. Perhaps this comes from a persisting effort to distance myself from being a “townie.” I like to think of it as pride in the furniture city, but then again maybe I just want to be from an exotic land. One just below the pinky in about the middle of the palm.

ArtPrize

Last summer, I wrote about public art and its usefulness from an urban perspective. Last month, I was back in Grand Rapids for a couple of days during ArtPrize and got to see some of the pieces around the city. While walking around downtown Grand Rapids, the difference between the ArtPrize approach and Lincoln’s more conservative approach to public art became even clearer. ArtPrize’s a very public displays and more festival like atmosphere drove home the superiority of the bold philosophy.

I was only in Grand Rapids for about a day and a half, maybe two full days when everything was put together, but I had to go and see ArtPrize. Publicity in national outlets like the New York Times and GQ tend to build that type of excitement. So I dragged my brother out on an overcast, chilly (and eventually a bit rainy) Friday afternoon and walked around the city’s downtown. Now, I was an out-of-towner with a very limited schedule. Poor weather wasn’t going to stop me from wandering the city to look at the big displays of art. However, I was struck by how many other people were walking around downtown. I assumed the city would be relatively dead because most productive members of society have things to do during business hours, even if it’s a Friday. Yet, significant numbers of people were milling around the ArtPrize venues. I imagine most of these people could have visited on another day when the weather was better or the time more convenient, but that is the genius behind ArtPrize. People go see it. People go downtown. People spend time (and money) in the city. There are disputes about what constitutes “art” in an open, crowdsourced art competition. But from an urban perspective, ArtPrize builds a spectacle that becomes a must see. And even the disputes are a good problem. When was the last time your local newspaper’s question of the day asked about what constitutes “art”?.

This impressive display of urban life (in a “dying” city no less) contrasted greatly with Lincoln’s recently installed artwork. Located in the recently constructed Union Plaza, I’ve seen the few pieces of art installed from afar and I would like to see them from closer up, but what’s my motivation? It’s just off the bike trail so I can wait until I am in the area with some time to kill. Right now, the art alone lacks the necessary pull to attract me to Union Plaza. Besides, once I head down there, what else is there to do? I could then go downtown, but little in close proximity as of now. If I want to have a night downtown, I’ll just travel downtown and leave the art for another time (or wait until a First Friday if I want to pair art with downtown). While Lincoln may connect its artwork to its urban scene in the future, right now, I would much rather enjoy the spectacle of ArtPrize, even if just for one cloudy afternoon.

Invest in Art

The Lincoln Journal Star is reporting today the Lincoln Partners for Public Art Development wants to turn Lincoln into a center for world class public art. First of all, I love the idea. Lincoln has a solid foundation of art from which it can build, including UNL’s Philip Johnson-designed Sheldon Museum of Art. And public investment in the arts reaps an even larger economic impact (Michigan has made $51 for every $1 apparently).

Even though the investment is quite encouraging (see these Journal Star articles for more on the abstract piece, giant head, and my favorite), for this investment to work the city must do more than attain and install world class art. A “build it and they will come may” attitude might work, but if I’m betting hundreds of thousands of dollars, I want better odds than “might.” So here’s my proposition, Lincoln. Buy and display the art. Then give people a reason to celebrate it.

I should add the disclaimer that my thinking is entirely colored by the experience of hometown, Grand Rapids, Michigan. In 1970, the year after the city installed Alexander Calder’s La Grande Vitesse, the city hosted the first Festival of the Arts which continues to attract thousands of area residents downtown for food, music, and lots of family friendly fun (the brochures write themselves). Grand Rapids has continued to invest in art, with the more recent Frederik Meijer Gardens & Sculpture Park, Rosa Parks Circle (near which the city’s art museum built an impressive new building), and most recently, ArtPrize, which brought a reported $15.4 million to the city in 2011.

Lincoln may not have the same benefactor class that helps enable Grand Rapids to undertake such bold projects, but Lincoln and its community members are clearly interested in investing in the city through the arts. I’m not suggesting Lincoln just create an ArtPrize-West, but giving people a reason to enjoy the city’s art is just as if not more important than having art throughout the city. Of course, this notion isn’t revolutionary to Lincoln. Just look at First Fridays, Jazz in June, or one of the many local music festivals (Zoofest was this very weekend). But if there is a plan to encourage the public’s interaction with these new works of public art, the plan needs to be touted alongside the proposed works of art themselves. An investment in public art will lead to a better quality of life for the residents of Lincoln. However, life in Lincoln will improve not just because art is beautiful or culturally enriching, but because art can bring tangible economic benefits and encourage further urban investment. So I hope to hear soon about Lincoln’s plan to celebrate (preferably yearly) its new influx of public art.

Urban Portal

Urban Portal catalogs seemingly every resource available online to urban scholars. The project’s main sections, emerging research and resources boast a large number of links with impressive search functions. Emerging research has two sections, “Issues” and “New & Noteworthy.” Issues are short scholarly examinations of socially relevant topics, like Does racial segregation hurt the poor?. New & Noteworthy collects news items related to urban issues. Resources organizes online resources into Data, including GIS data sets, Events, Journals, Links (to things like H-Urban, Historypin, and Hyper cities, and Organizations (108 listed when I visited). Those in the Chicago area may also be interested in the At UChicago section, which narrows the resources to those at the University of Chicago.

While Urban Portal’s greatest benefit for scholars is its comprehensiveness (so many links for me to click on), the feature I am most excited about is the project’s engagement in public issues. Collecting resources and news events is incredibly useful to academics, but the application of scholarly research on urban issues represents the kind of public outreach in which scholars ought to engage.