Categories

# The Full Graphing Monty – R

Spent the entire day bashing out graphs (not a euphemism at all).

I did some pretty intense node analysis, and then some plotting.

This what I used for plotting

```

## Convert to user list with stats
colnames(dfg7.2)<-c("x","x")
dfg7.2NL<-rbind(dfg7.2,dfg7.2)
dfg7.2NL<-as.data.frame(table(dfg7.2NL))
dfg7.2NL<-dfg7.2NL[with(dfg7.2NL,order(-Freq)),]
rownames(dfg7.2NL) <- 1:nrow(dfg7.2NL)
colnames(dfg7.2NL)<-c("user","Freq")
dfg7.2NL\$pcp <- dfg7.2NL\$Freq/sum(dfg7.2NL\$Freq)
dfg7.2NL\$cumSum <- cumsum(dfg7.2NL\$pcp)

## Place each user into core/middle/periphery
dfg7.2NL\$perc <-"NA"
dfg7.2NL\$perc[(dfg7.2NL\$cumSum)<=0.33] <- 1
dfg7.2NL\$perc[(dfg7.2NL\$cumSum) > 0.33 & (dfg7.2NL\$cumSum) <= 0.66] <- 2
dfg7.2NL\$perc[(dfg7.2NL\$cumSum) > 0.66] <- 3

## Place Core/Middle/Periphery user names into sets
set1<-c(t(subset(dfg7.2NL, perc == 1, select = user)))
set2<-c(t(subset(dfg7.2NL, perc == 2, select = user)))
set3<-c(t(subset(dfg7.2NL, perc == 3, select = user)))

## Create graph from original Data Frame
g7.2<-graph.data.frame(dfg7.2,directed=FALSE)

## Simplify graph
sg7.2<-simplify(g7.2)

## change node color and size according to above sets
V(sg7.2)[set1]\$color <- "#2244CC"
V(sg7.2)[set2]\$color <- "#3388EE"
V(sg7.2)[set1]\$size <- 4
V(sg7.2)[set2]\$size <- 3
V(sg7.2)[set3]\$size <- 1
V(sg7.2)[set1]\$bcol <- "#000088"
V(sg7.2)[set2]\$bcol <- "#1166CC"
V(sg7.2)[set3]\$bcol <- NA

## Save SVG graph
svg("/location/of/svg/sg7.2.svg")
draw.quick.graph(sg7.2)
dev.off()

## Save graph as table
write.csv(dfg7.2NL,"/location/of/table/dfg7.2NL.txt",row.names=FALSE)

## Quick look to see it's all there
draw.quick.graph(sg7.2)

```

This is the final result — one of the smaller graphs. Just as a final note. I freaking LOVE MacVim.