我正在修改一个ggnet
对象ggplot2
来增加节点的大小。但是,如果我使用这种方法,我无法设法在图例中包含 size 参数。我已经尝试过scale_size_manual
在方法中包含大小,aes
但仍然没有成功。
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
在这里,我将ggplot2
函数添加到ggnet
并包含 size outside aes
。我正在努力拥有 size 参数的图例
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()