Включить легенду о размере узла объекта ggnet2, модифицированного с помощью ggplot - PullRequest
0 голосов
/ 27 марта 2020

Я изменяю объект ggnet, используя ggplot2, чтобы увеличить размер узлов. Однако, если я использую этот подход, мне не удастся включить параметр размера в легенду. Я пробовал 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 и включаю размер вне aes. Я изо всех сил пытаюсь получить легенду о параметре размера

 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()
...