0

In R, the netgraph() function takes a cex.points argument that controls the appearance of the points in the plot. Is there a way to scale the size of points through a variable in my .excel?

Thank u all

I don't know the arguments

Derro
  • 1
  • I don't understand what you mean by *"my .excel"*. Please edit the question with a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). Are you looking for `netgraph(net1, points = TRUE, cex.points = 3)`? – Rui Barradas Apr 03 '22 at 11:48
  • Thank you so much for your reply! In fact I was not clear. I would like the size of the point to be proportional to the number of observations in the single node (in my case the number of patients). Is there a way to do it automatically? – Derro Apr 03 '22 at 13:06

2 Answers2

0

It's not clear what you mean by "scaling the points by a variable in my Excel", and if you are unsure of the arguments, you could have a look at ?netgraph.

Suppose you had a vector of point sizes like this:

my_point_sizes <- c(1, 1, 2, 1, 4, 1, 6, 2, 1, 1)

And a netmeta object like this:

library(netmeta)

load(system.file("/data/Senn2013.rda", package = "netmeta"))

net1 <- netmeta(TE, seTE, treat1, treat2, studlab,
                data = Senn2013, sm = "MD", reference = "plac")

Then you can apply the sizes to the points like this:

netgraph(net1, points = TRUE, cex.points = my_point_sizes)

Created on 2022-04-03 by the reprex package (v2.0.1)

Allan Cameron
  • 147,086
  • 7
  • 49
  • 87
  • Thank you so much for your reply! In fact I was not clear. I would like the size of the point to be proportional to the number of observations in the single node (in my case the number of patients). Is there a way to do it automatically? – Derro Apr 03 '22 at 13:05
  • Hi Derro. That's why it's good to include a reproducible example in your question. Could you perhaps type `dput(df)` into your R console (except change `df` to the name of your own data frame), then copy / paste the result into the question? (Obviously remove any patient identifiable data before doing so) – Allan Cameron Apr 03 '22 at 14:46
0

Here is a way to plot the points with sizes defined by the data. Function netmeta is a list of S3 class "netmeta" and has two members treat1 and treat2.

Base R function table can compute the frequencies but since they are the frequencies of two vectors, the two vectors must be combined to a 1-dim vector. This is done with c().

suppressPackageStartupMessages(library(netmeta))

data(Senn2013)
net1 <- netmeta(TE, seTE, treat1, treat2, studlab,
                data = Senn2013, sm = "MD", reference = "plac")

# points size proportional to data frequencies
pts_size <- table(c(net1$treat1, net1$treat2))

netgraph(net1, points = TRUE, cex.points = pts_size)

Created on 2022-04-03 by the reprex package (v2.0.1)

Rui Barradas
  • 70,273
  • 8
  • 34
  • 66