R 包括使用ggplot修改的ggnet2对象的节点大小图例
我正在使用R 包括使用ggplot修改的ggnet2对象的节点大小图例,r,ggplot2,ggnetwork,R,Ggplot2,Ggnetwork,我正在使用ggplot2修改aggnet对象以增加节点的大小。但是,如果使用这种方法,则无法在图例中包含尺寸参数。我尝试了scale\u size\u手册和将大小包含在aes方法中,但仍然没有成功 library(network) library(dplyr) library(ggplot2) library(GGally) # weighted adjacency matrix bip = data.frame(event1 = c(1, 2, 1, 0),
ggplot2
修改aggnet
对象以增加节点的大小。但是,如果使用这种方法,则无法在图例中包含尺寸参数。我尝试了scale\u size\u手册
和将大小包含在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
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()