Reputation: 431
I currently use following script to create a plot for betweenness centrality:
plot(g,
rescale = FALSE,
edge.color= edge_color,
edge.width=E(g)$Weight*0.5,
vertex.size= degree(g)*0.5,
main="Degree Centrality"
)
As you can see, I currently use a simple multiplier to adjust vertex.size
. As some nodes are really big and some seem too small, I would like to set a range with a minimum and maximum size. Of course, that range should consider degree(g).
Is that somehow possible?
Note: Attempts with scale (degree(g), 5, 15)
or similar did not work: "Error in symbols(x = coords[, 1], y = coords[, 2], bg = vertex.color, :
invalid symbol parameter"
Upvotes: 3
Views: 4005
Reputation: 94162
To rescale numbers, x, with a domain of (a,b) to a range of (c,d) you need to make a rescaling function like:
rescale = function(x,a,b,c,d){c + (x-a)/(b-a)*(d-c)}
So then if you have degree sizes from 0 to 200, and want your vertex sizes to range from 1 to 5 units, specify the vertex size with:
rescale(degree(g), 0, 200, 1, 5)
This is just a simple linear transformation - you might want something non-linear for better visuals.
You might find a rescale
function in a package somewhere (like the rescale
function in the scales
package), but its not what scale
does!
Upvotes: 7