r - ggnetwork scale edge and node (vertex) size independently (different geoms different scales) -


problem:

i want use different size scale edges , nodes in network created ggnetwork package. if @ image below may think did since have different sizes in fact edge , node size not scaled independently in plot. both scaled scale_size_area() function towards same maximum (30). if larger nodes edges shrink. guess problem boils down scaling size of different geoms different functions. example how can scale size of nodes scale_size_area(max_size = 30) , size of edges scale_size_continuous(range = c(1,6))?

example code:

#load packages library(network) library(sna) library(ggplot2) library(ggnetwork)  #create data #data edges edge_df<-data.frame(group1=c("a","a","b"),            group2=c("b","c","c"),            connection_strength=c(1,2,3))  #data nodes/vertexes vertex_df<-data.frame(group=c("a","b","c"),                       groupsize=c(2,3,4))  #create network my_network<-network(edge_df[,1:2],directed = false)  #add edge attribute (interaction strength) network object set.edge.attribute(my_network, "connection_strength", edge_df$connection_strength)  #add node/vertex info network object special %v% operator my_network %v% "groupsize" = vertex_df$groupsize   #plot ggplot(my_network, aes(x = x, y = y, xend = xend, yend = yend,color=vertex.names)) +   #edge size depends on connection strength   geom_edges(color = "black",aes(size=connection_strength/20)) +   #node size depends on groupsize   geom_nodes(aes(size=groupsize)) +   #scale size area nodesize want different scaling edges   scale_size_area(max_size = 30,guide=f)+   scale_color_discrete(guide=f)+#remove colour legend   scale_x_continuous(limits=c(-0.15,1.15))+#add space x-axis   scale_y_continuous(limits=c(-0.15,1.15))+#add space y-axis   theme_bw()#simple plot layout 

example plot:

example network plot

almost duplicate of this question.

i'm not ggplot2 expert, far understand, dual-scaling (e.g. having 2 y-axes or 2 color scales) contradicts grammar of graphics.

the solution aforementioned question might work, it's hack.


Comments

Popular posts from this blog

Load Balancing in Bluemix using custom domain and DNS SRV records -

oracle - pls-00402 alias required in select list of cursor to avoid duplicate column names -

python - Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] error -