# Example with a random graph --------------------------------------------------
set.seed(1231)
# Random scale-free diffusion network
x <- rdiffnet(1000, 4, seed.graph="scale-free", seed.p.adopt = .025,
rewire = FALSE, seed.nodes = "central",
rgraph.arg=list(self=FALSE, m=4),
threshold.dist = function(id) runif(1,.2,.4))
# Diffusion map (no random toa)
dm0 <- diffusionMap(x, kde2d.args=list(n=150, h=.5), layout=igraph::layout_with_fr)
# Random
diffnet.toa(x) <- sample(x$toa, size = nnodes(x))
# Diffusion map (random toa)
dm1 <- diffusionMap(x, layout = dm0$coords, kde2d.args=list(n=150, h=.5))
oldpar <- par(no.readonly = TRUE)
col <- colorRampPalette(blues9)(100)
par(mfrow=c(1,2), oma=c(1,0,0,0))
image(dm0, col=col, main="Non-random Times of Adoption\nAdoption from the core.")
image(dm1, col=col, main="Random Times of Adoption")
par(mfrow=c(1,1))
mtext("Both networks have the same distribution on times of adoption", 1,
outer = TRUE)
par(oldpar)
# Example with Brazilian Farmers --------------------------------------------
## Not run:
# dn <- brfarmersDiffNet
#
# # Setting last TOA as NA
# diffnet.toa(dn)[dn$toa == max(dn$toa)] <-
# NA
#
# # Coordinates
# coords <- sna::gplot.layout.fruchtermanreingold(
# as.matrix(dn$graph[[1]]), layout.par=NULL
# )
#
# # Plotting diffusion
# plot_diffnet2(dn, layout=coords, vertex.size = 300)
#
# # Adding diffusion map
# out <- diffusionMap(dn, layout=coords, kde2d.args=list(n=100, h=50))
# col <- adjustcolor(colorRampPalette(c("white","lightblue", "yellow", "red"))(100),.5)
# with(out$map, .filled.contour(x,y,z,pretty(range(z), 100),col))
# ## End(Not run)
Run the code above in your browser using DataLab