Skip to content

Instantly share code, notes, and snippets.

@chrisnatali
Created March 20, 2014 16:47
Show Gist options
  • Save chrisnatali/9668372 to your computer and use it in GitHub Desktop.
Save chrisnatali/9668372 to your computer and use it in GitHub Desktop.
quick plot of graph to png file
my_g_plot <- function(g, id, transform=FALSE) {
# get coords in mercator proj
png(paste("plots/plot", id, ".png", sep=""),
type="cairo-png",
width=1000, height=1000)
if(transform) {
vec_df <- get.data.frame(g, what="vertices")
xy <- vec_df[,c("X", "Y")]
coordinates(xy) <- ~X+Y
proj4string(xy) <- CRS("+proj=longlat +ellps=WGS84")
xy <- spTransform(xy, CRS("+proj=merc +ellps=WGS84"))
plot(g, layout=xy@coords, vertex.size=4, edge.arrow.size=1)
} else {
plot(g, vertex.size=4, edge.arrow.size=1)
}
dev.off()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment