Neat R Package for Graphing Facebook Friend Networks


SNaPP Lab alumnus Drew Engelhardt showed me a cool new package in R yesterday that lets users connect to Facebook’s Graph API and access their facebook info and friend networks from R. I had fun with it, so I thought I’d write up a walkthrough for anyone who might be interested in poking around with R over break. (This doesn’t really assume any prior R knowledge and is based off of this code)

First step – install and open R (

Second step – copy and paste the following R code into a text editor

Third step – follow the instructions in the R code. The only thing you need to add to the code is where it says “token” you need to go to Facebook and generate your own access code. Once you’ve pasted the token into the correct place in the code, select all of the code, paste it into the R syntax window, and hit enter.

# Playing around with Rfacebook - 12.20.2013
# Created by : Meg Schwenzfeier
# Adapted from: Pablo Barbera - 

# Set the "Working Directory" - this is just the folder that R will work
# out of and save things into. Just put the file extension of whichever
# folder you want in quotes.


# Installing a few packages. Packages are add-ons to R that help it do
# functions that aren't built-in. ONLY RUN THESE ONCE

# Load libraries - now the packages are installed, you just have to 
# load them

# Now go login to facebook and go here to generate a Graph API Explorer 
# access token. It's a long string that will let you access facebook 
# info from R.

# Paste the token in between the quotation marks below. Now R has your 
# access token stored as 'token'

    token = "###############"

# Now you can get your friend network using the getFriends() and 
# getNetwork() functions

    # This is just a list of your friends
    friends <- getFriends(token, simplify = TRUE)

    # This is your friend network - this might take a while
    friend_network <- getNetwork(token, format = "adj.matrix")

# Turn the facebook data into an adjacency matrix using the igraph package
    friend_network <- graph.adjacency(friend_network, mode = "undirected")

# Now you can create the layout for the network by passing the network 
# through the fruchterman reingold function, which sets up where the 
# nodes are laid out in the eventual network graph

    l <- layout.fruchterman.reingold(friend_network)

# Want to color your matrix by groups? Run this function to detect 
# clusters in your network

    cluster <-

# Create the dataframe with all of the information created so far. Data 
# frames in R are basically like excel spreadsheets

    network_data <- data.frame(l); names (network_data) <- c("x", "y")
    network_data$cluster <- factor(cluster$membership)
    network_data$name <- friends$name

# Creating a list of connecting lines (edges) for the network
    connectors <- get.edgelist(friend_network, names = FALSE)
    connections <- data.frame(network_data[connectors[,1], c("x", "y")], network_data[connectors[,2], c("x", "y")])
    names(connections) <- c("x", "y", "x2", "y2")

# Now you can plot it!

    # plotting the basic network
    network_plot <- ggplot(network_data, aes(x = x, y = y, color = 

    # adding the connectors
    network_plot <- network_plot + geom_segment(aes(x = x, y = y, 
            xend = x2, yend = y2), data = connections, size = 0.25, 
            color = "grey", alpha = 1/3) + geom_point()

    # Cleaning it up a little bit and adding a title
    network_plot <- network_plot + ggtitle("Facebook Friend Network") + 
           xlab("") + ylab("") + theme(axis.text.y = element_blank(), 
           axis.text.x = element_blank(), axis.ticks = element_blank(),
           panel.background = element_rect(fill="white"), 
           legend.position = "none")

    # look at the plot

How the Obamacare Team is looking to the Future

For the past several months the Obamacare Team has been working on a massive data-collection project. The goal of the endeavor is to compile every state-level media piece discussing health reform in the month of August 2009. These articles are to be processed via automated content analysis to produce meaningful summaries of media coverage during this important part of the saga that was passage of the Affordable Care Act (ACA). We are making slow but steady progress with this endeavor, and plan to have it completed by the end of Christmas break.

In the meantime, however, our team has already laid the groundwork to use this data to investigate areas of interest to us.

For instance, our very own Joanna Borman is planning on potentially spending time next semester investigating connections between the news media data we are collecting and Senate election results for 2010. Her goal is to determine if state media coverage prefaced any interesting statewide election results, particularly given the rise of the Tea Party movement around this time.

Team member Will Evans, on the other hand, has made plans to potentially study ties between state media coverage and newspaper readership/issue framing. His goal with this project is to identify trends in the data that may be caused by who is reading what sources of news and how key issues are framed in articles discussing Obamacare.

I myself plan on spending a significant amount of time next semester gathering data on key policy outcomes and healthcare indicators to compare against media coverage and state-level public opinion of Obamacare. Policy outcomes includes state decisions on whether or not to expand Medicaid, join the multitude of lawsuits against the ACA, set up their own insurance exchange, and much more. These factors are important because they have the potential to significantly influence how citizens perceive and react to the health reform law. In terms of healthcare indicators, I want to collect data on various measures of the quality and cost of medical care within states, as well as how healthy states’ populations are. I then hope to run these data against state media coverage to see if there is some connection between media coverage and the quality of healthcare in a state.

While each member of the team has made tentative plans for what to study next semester, the reality is that these plans are not set in stone. We understand that we will have to react and adapt to obstacles that arise in data collection and analysis. Yet, on the whole, the descriptions above describe where our team wishes to go in the spring, and we are excited to get started.

Framing on Facebook: A Summer Research Project

This past summer I took advantage of a research grant opportunity to look into something of personal interest to me. The idea of elite framing, where leaders (both political and non-political) talk about major issues in such a way as to change how the public perceives them, has fascinated me ever since freshman year. In one of the first classes I took here at W&M, we read about opponents of the estate tax proposed in the early 2000’s framed the tax as a “death tax.” By doing so, they changed public perception of the tax and got people the tax would never have effected to come out against it. I wanted to study this framing phenomenon more. I picked a policy issue of interest to me (the Affordable Care Act, or “Obamacare”), submitted a proposal (with guidance from my project advisor, Professor Jaime Settle in the Government Department, and was awarded the grant.


Armed with funding, 3 months off of school, and a kitchen fully stocked with my mom’s home-cooked food, it was time to hit the ground running.


I began my project by defining my research question. To make the endeavor feasible, I limited political elites to Congress (House of Representatives and Senate), since I am personally interested in Congress. I then narrowed framing down to social media, and specifically Facebook (because of how much data is publically available), because these media were underrepresented in the literature on elite framing. Having chosen Obamacare as my issue case study, I further condensed my research to look at the period of July 18-August 18, 2009, a month-long period with significant data available because of the August recess town halls. Finally, I established public opinion on three dominant “frames” in the Obamacare debate (cost, choice, and quality of care) as the dependent variable side of my analysis.


Data collection came next, and with it some tedium unavoidable in these kinds of projects. I first collected data on every Facebook post made by Senator/Representative on Obamacare between July 18-August 18, 2009. I used this data (as well as the partisan leanings of each state) to choose three case studies: Texas, California, and Florida. For these states, I determined how many of the Facebook posts made by the state’s Senators and Representatives were focused on each of the three frames in my independent variable (cost, choice, quality). Finally, I pulled polling data from the Kaiser Family Foundation’s Health Tracking Poll (HTP) on how people in three case study states felt about Obamacare in terms of those three frames over the course of the summer of 2009. I concluded by conducting trend analysis to see if people became more/less polarized on issue questions related to those three frames.


In the end, I did not find evidence to support the hypothesis that increased focus by elites on a particular issue frame would make the public in their state more polarized along that dimension of the issue. I did, however, find evidence suggesting that citizens in the three case study states became more polarized on all three of the frames over the course of the summer, which suggests the media storm surrounding health reform across those 3 months significantly influenced the public’s attitudes towards Obamacare.


Looking back, there are many ways I or someone else could improve this project. The relationships I found were likely muted for a number of reasons ranging from the possibility that few people care about what their Congressional delegation says on Facebook to the limits of using on Facebook to conduct my analysis. These were also numerous obvious shortcomings like hand-coding Facebook posts, the high number of Representatives/Senators with no Facebook profiles at the time, and the fact that I only used two iterations of the Health Tracking Poll. Yet in the end, I’m satisfied with how the project turned out. It taught me so much about how to design a research project, collect appropriate data, and present findings. I am very thankful I had the opportunity to complete this project.

Against the Quantitative Turn in Political Science

In doing readings and conducting literature reviews for both the SNaPP Lab and other government courses, one dominant trend in contemporary political science emerges: Theory is out, quantitative research is in.

At first glance, this quantitative turn in political science would seem to be a positive development. Theory guided works often appear impenetrable, given to subjective interpretation, and unable to provide practical policy solutions. The rise of quantitative research in political science offers the emancipatory hope that the pernicious subjectivity so endemic to the social sciences can be partially overcome. Speculative theory can be replaced by an objective and systematic method of inquiry that allows the discipline to better address the practical, everyday needs of people.

It sounds nice, but an actual look through contemporary political science research leaves one a little less optimistic about the discipline’s new passion for empiricism. Studies replete with advanced statistical techniques and computational models have produced, as Ziliak and McCloskey call it, a “cult of statistical significance” that has allowed the profession to skirt the fundamental questions in favor of limited debates over measurement or method that fail to tell us much at all.

This isn’t to bash all empirical research in the social sciences. Quantitative research can be endlessly illuminating and the advent of computers has given academics the ability to quantify and interpret a greater breadth of information than at any time in human history. But without any underlying theory or principle to guide the questions being asked, researchers will continue to find themselves awash with data but powerless to make it mean anything.

Political scientists would do well to pay attention to the warning Hannah Arendt put forth some forty years ago: “The need of reason is not inspired by the quest for truth but by the quest for meaning. And truth and meaning are not the same.” As humans, we find value and meaning in the political. The power of political science is that it allows us to better understand the human condition by examining the ways in which we forge self-knowledge and purpose through our engagement in public discourse and the political process. A political science discipline which ignores this fact does so at its own peril.

A College Sophomore’s Reflection on the College Sophomore Problem

Introductory Psychology, a class most all college students end up taking. A typical Intro class at William & Mary is anywhere from 75-200 students. Part of every intro psych course is the “required outside study participation”; in essence professors make their intro students participate in their own, their colleagues, or their grad/undergrad students psychology experiments. By requiring this of every psych student, the department is able to guarantee that they will have a large population from which to pull their experiment data, and they can get participants for free (because it is required by intro classes). But there has to be a catch, it can’t be this easy to get a representative sample of people to accurately extend the findings of an experiment to all of humankind!

Well, its not.

From personal experience I can tell you that sophomores at William & Mary are anything but a representative sample for the rest of the US. To say the least a T.W.A.M.P. (typical W&M person) is not a typical person. For one, William & Mary students are high-stress, high-strung, and very competitive. We as students live from deadline to deadline, trying to make it through the semester one paper at a time. We interact with other people our age with the exception of professors and the nice ladies that swipe ID cards at Sadler. We all live in a bubble.We see the world in 15 week intervals (semesters). Most of us we are still learning to live independently of our parents. We live in Williamsburg, an area with very little crime. We all have the same job, being students. And we can all speak at length about our own personal struggles to register for classes on Banner. Ultimately, the William & Mary student (or any college student for that matter) lives in a very unique time of life, a time of self discovery, independence, and transition into “adult” life which ultimately makes the college student population an unrepresentative sample.


Planning an Honors Thesis

Writing an honors thesis is undoubtedly a valuable experience and a great way to end your undergraduate career.  While it is certainly a big undertaking not for the faint of heart, you develop incredible skills along the way and if you truly love your topic, you will enjoy the process.  Starting the process of writing a thesis can be daunting, so here are some general tips to get you started.

1. Brainstorm. Yes, brainstorm. Go back to your elementary school days, get a piece of paper and a pen and just write.  You can even add drawings of lightning bolts to illustrate your brainstorm, if you’re so inclined.  If you’re looking to write a thesis in political science, make a list about what interests you about politics. Why did you choose to study political science? What news stories get you worked up? Why is that? Which classes have you found particularly interesting?

2. Evaluate. Take a look at your brainstormed list and think about which of these topics you could study.  If two or three ideas are jumping out at you, take a look into the literature to see what has been written on it.  This might lead you to develop a more concrete idea about which direction to take your research in.  It might also help to jot down a few notes while you’re reading to see what we know about your topic and what we don’t know.

3. Chat. Chat with a professor and/or advisor about your thesis topic ideas. This person does not have to necessarily be your ultimate thesis advisor, but talking about your ideas with a faculty member is really important.  They will be able to help steer you toward more literature to look at and other faculty members with expertise in your interest area.  It’s also a good idea to chat with some seniors or recent graduates who are writing or wrote theses to see what they think of your topic and to bounce some ideas around.

4. Specify. At this point, your nebulous thesis topic should be starting to take the form of a research question.  It doesn’t have to be pretty and polished yet, but you should know which concepts you are trying to understand with your thesis.  Now would be a good time to start thinking about how you are going to answer your question.  What data will you need? How will you get it? What tools will you need to accomplish it?  Figuring out the answers to these questions will help you determine the feasibility of your project and (if necessary) help you rework your research question so it is feasible to accomplish given the time and resources you have to complete the thesis.

5. Propose. You don’t have to get down on one knee, but you will certainly be making a commitment to this thesis, and your proposal is of utmost importance.  Although most departments do not require a lengthy proposal, it will undoubtedly help you really think through the details of your project if you write out a detailed proposal of your thesis.  Some good sections to include are:

  • Statement of Research Question
  • Literature Review
  • Why you care about the project
  • Why we should care about the project
  • Theory
  • Hypotheses
  • Empirical Strategy (unit of analysis, scope of analysis, variable constructs, data collection for dependent variable)
  • Data sources
  • Validity (construct, internal, external)

6. Solicit Feedback. As you are writing out your proposal, you will probably want to start thinking about who your thesis advisor will be–and ask early!  Think of a professor you have a good relationship with and who has expertise in your interest area. Advising an honors thesis is a pretty large time commitment for faculty members, so make sure that you ask potential advisors early on.  Have your advisor take a look at your proposal and get some feedback! You should also ask for feedback from your peers. It’s much better to get this feedback early, before you’ve started data collection, than in April of your senior year, when there’s no time left to fix it.

7. Funding.  If you think you want to work on your thesis over the summer before your senior year, you should think about applying for a Charles Center Summer Scholarship or an Honors Fellowship. More information about these awesome opportunities can be found here. You should also check out this page for more information on deadlines and the bureaucratic side of writing a thesis.

Best of luck to you as you embark on your honors thesis journey! It truly has been an incredible experience for me so far and I hope that you consider taking advantage of this opportunity.

Gender in Online Political Discussions

In conducting research on how and why people engage in political discussion on social media sites, I found myself continually wondering about the question of gender. What interested me wasn’t the demographics of social media users–we know that the average user of social media is female and in the 18-24 age bracket–but rather the ways in which gender might structure political debate online.

A wide body of literature exists which suggests that women in positions of power are expected to conform to traditional conceptions of femininity. This often causes women to be evaluated differently than men for performing the same task. For example, a 1979 study by Rhoda Unger showed that female professors who were considered harsh graders were not perceived as being “nice” and “nurturant” and as such received lower evaluation scores. Men who were perceived as harsh graders, however, did not experience a commensurate drop in their evaluation scores. In addition, other studies have shown that female instructors who are perceived as being unsociable and unfriendly receive substantially worse evaluations than female instructors who are considered warm and friendly. In contrast, male instructors were given better evaluations when they were perceived as being unfriendly (Kierstead et al., 1988). These pernicious stereotypes regarding what constitutes appropriate behavior for each gender likewise manifest themselves in public political discourse; numerous studies have shown that female leaders are devalued when they employ direct and assertive governing tactics that are traditionally associated with masculinity (Eagly, Makhijani and Klonsky, 1992).

As such, it seems only natural to posit whether these disparities in how men and women are evaluated persist on social media sites. Are women who engage in heated political discourse online viewed differently than men who do the same? Are impassioned political arguments made by women online considered less authoritative? Less informed? What is the general perception of women who are opinion leaders within a particular online social network?

Unfortunately, there is a large absence of available research on the topic. This only serves, however, to make the issue of gender in online political debate a more interesting and fruitful area for us to explore through further reading, surveying, and experimentation!