lundi 19 août 2019

Display legend levels based on criteria

I have a network chart created with the igraph package and I would like to add a legend to it, showing the various names of nodes displayed in the network.

I have the following code, which produces a legend with all the levels in the $Group_Name column.

legend("topleft",legend = levels(as.factor(V(net)$Group_Name)),col = net_pal,bty = "n")

However, I would like to only display those $Group_Names that have a corresponding Y value in another column (Core_Group).

I was thinking something like this:

legend("topleft",legend = if_else(V(net)$Core_Group =="Y", levels(as.factor(V(net)$Group_Name)), as.character(NA)),col = net_pal,bty = "n")

But that returns the following error: Error:truemust be length 79 (length ofcondition) or one, not 33

Is there a way to conditionally display the levels in the legend?

Aucun commentaire:

Enregistrer un commentaire