Reputation: 1659
I am modifying the a ggnet
object using ggplot2
to increase the size of the nodes. However, if I use this approach I cannot manage to include the size parameter in a legend. I have tried the scale_size_manual
and including size within aes
approaches but still not successful.
library(network)
library(dplyr)
library(ggplot2)
library(GGally)
# weighted adjacency matrix
bip = data.frame(event1 = c(1, 2, 1, 0),
event2 = c(0, 0, 3, 0),
event3 = c(1, 1, 0, 4),
row.names = letters[1:4])
# weighted bipartite network
bip = network(bip,
matrix.type = "bipartite",
ignore.eval = FALSE,
names.eval = "weights")
# set colors for each mode
col = c("actor" = "grey", "event" = "gold")
## I have tried including the size in the ggnet2 but the points are not as big as I want
p <- ggnet2(bip, color = "mode", label = F, shape = "mode",
palette = col,
shape.palette=c(24,19))
## add a size variable to the network data
p$data <- p$data %>%
mutate(index=1:7)
## create a vector of the sizes
aa <- p$data$index
Here I add the ggplot2
functions to ggnet
and include size outside aes
. I am struggling to have a legend of the size parameter
p +
geom_point(aes(color = color, shape=shape), size = aa*2, color = "#92D050") +
geom_point(aes(color = color), alpha = 0.1) +
geom_text(aes(label = toupper(label )), color = "black", fontface = "bold", size=3 ,
position = position_nudge(y = -0.015)) +
scale_size_manual(name="Antigen" ,values=p$data$index ,
guide = "legend",
guide_legend(override.aes = list(size=c(1,2,3,4,5,6,7)))) +
guides(color = FALSE) +
theme_minimal()
Upvotes: 1
Views: 358