Rnaldinho - 4 months ago 61

R Question

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`

Is that somehow possible?

Note: Attempts with

`scale (degree(g), 5, 15)`

invalid symbol parameter"

Answer

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!