问题描述
我想根据与该节点关联的值为节点创建不同的大小。
我得到的是这些怪异的数字表情符号,而不是我期望的图例标签。
我在Linux机器上使用RStudio服务器,但ggplot没有出现此错误
这是我的可视化
这是我的代码
library(GGraph)
library(network)
netval1 <-
network(netmat1_matrix,matrix.type = "edgelist")
netval1_tidy <-
as_tbl_graph(netval1)
ggraph(netval1_tidy) +
geom_edge_link() +
geom_node_point(aes(size = (c))) +
theme_graph()
这是我的数据
structure(c(1,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,NA,246,2),.Dim = c(1227L,3L),.Dimnames = list(
NULL,c("a","b","c")))
解决方法
您的审美c
在这里似乎是一个问题。请考虑以下示例数据。
num_nodes <- 10
my_sociomatrix <- matrix(round(runif(num_nodes*num_nodes)),# edge values
nrow = num_nodes,#nrow must be same as ncol
ncol = num_nodes)
diag(my_sociomatrix) <- 0
net <- as.network(x = my_sociomatrix,# the network object
directed = TRUE,# specify whether the network is directed
loops = FALSE,# do we allow self ties (should not allow them)
matrix.type = "adjacency" # the type of input
)
network.vertex.names(net) <- LETTERS[1:10]
# Create the variable
gender <- c(rep("Female",num_nodes/2),rep("Male",num_nodes/2))
# Add it to the network object
set.vertex.attribute(net,# the name of the network object
"Gender",# the name we want to reference the variable by in that object
gender # the value we are giving that variable
)
age <- round(rnorm(num_nodes,20,3))
set.vertex.attribute(net,"Age",age)
summary.network(net,# the network we want to look at
print.adj = FALSE # if TRUE then this will print out the whole adjacency matrix.
)
使用图形程序
ggraph(net) +
geom_edge_link() +
geom_node_point(aes(size=age/5)) +
theme_graph()