SachaEpskamp / qgraph

Developmental version of qgraph
GNU General Public License v2.0
68 stars 21 forks source link

Pie on node not showing if using subplots #65

Closed Rhydderch closed 1 year ago

Rhydderch commented 1 year ago

Dear Sacha,

Qgraph is really a godsend, and I'm enjoying pushing its limits. It's great to show a lot of information at once.

I realized I am not able to subplots combined with the "pie" function.

the following code shows the pie border:

qgraph(TE_matrix, 
       edgelist = TRUE,
       weighted = TRUE,
       nNodes = length(variables_names),
       edge.labels = TRUE,
       labels = FALSE,
       shape = "square",
       vsize = 10,
       esize = 1,
       asize = 2,
       edge.width = 10,
       #labels = variables_names,
       title = paste0("max lag ", df_allTE_subset$current_value[[1]][[2]]," analysis"),
       #border.width = border_with_TE_omnibus$omnibus_te*10,
       #subplots = subplots_list,
       images = list(NA, NA, NA, NA, NA, NA),
       mar = c(4, 4, 4, 4),
       pie = list(c(0.34,0.45), 0.54, 0.23, 0.43, 0.8, 0.2),
       pieBorder = 0.2
)
image

However, if I uncomment the "subplots" arguments, this is the result:

qgraph(TE_matrix, 
       edgelist = TRUE,
       weighted = TRUE,
       nNodes = length(variables_names),
       edge.labels = TRUE,
       labels = FALSE,
       shape = "square",
       vsize = 10,
       esize = 1,
       asize = 2,
       edge.width = 10,
       #labels = variables_names,
       title = paste0("max lag ", df_allTE_subset$current_value[[1]][[2]]," analysis"),
       #border.width = border_with_TE_omnibus$omnibus_te*10,
       subplots = subplots_list,
       images = list(NA, NA, NA, NA, NA, NA),
       mar = c(4, 4, 4, 4),
       pie = list(c(0.34,0.45), 0.54, 0.23, 0.43, 0.8, 0.2),
       pieBorder = 0.2
)
image

Would there be a way to use both together?

SachaEpskamp commented 1 year ago

This is hard to do in a single qgraph call because the suplot fills the entire node, but you can just make one plot for the pie charts and plot the subplots on top with an empty network and smaller node sizes:


 # Weights matrix:
mat <- matrix(rnorm(5^2),5,5)

# Suplots:
sp <- list(
  expression(plot(rnorm(100),rnorm(100),xlab="",ylab="",axes=FALSE)),
  expression(plot(rnorm(100),rnorm(100),xlab="",ylab="",axes=FALSE)),
  expression(plot(rnorm(100),rnorm(100),xlab="",ylab="",axes=FALSE)),
  expression(plot(rnorm(100),rnorm(100),xlab="",ylab="",axes=FALSE)),
  expression(plot(rnorm(100),rnorm(100),xlab="",ylab="",axes=FALSE))
)

# Plot the network with pie charts:
Q <- qgraph(mat,
       pie=runif(5),
       vsize = 10,
       shape = "square",
       labels=FALSE
       )

# Plot the subplots:
qgraph(matrix(0,5,5),
       vsize = 9,
       shape = "square",
       labels=FALSE,
       plot=FALSE,
       layout = Q$layout,
       subplots = sp
)
Rhydderch commented 1 year ago

Thanks a lot! It worked.

image