Customized Circle packing with R and ggraph - error saying the data frame should contain at least two columns - Stack Overflow

I am trying to create a circle packing figure, and keep getting the following error message:"Erro

I am trying to create a circle packing figure, and keep getting the following error message:

"Error in graph_from_data_frame(edges, vertices = vertices) : 
 the data frame should contain at least two columns"

I am trying to create a circles for the HPV variants that exist in HPVseq_p and then subcircles for those that exist in HPVseq_s. (ie a big circle for HPV16 that then contains the various HPV variants inside it for HPVseq_s (HPV16, HPV53)

my code is below:

library(ggraph)
library(igraph)
library(tidyverse)
library(viridis)    
edges <- HPV_subtypes$HPVseq_p
vertices <- HPV_subtypes$HPVseq_s
mygraph <- graph_from_data_frame(edges, vertices=vertices)`

dput(mydata_compressed)
structure(list(Sample = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), HPVseq_p = c("HPV16", 
"HPV16", "HPV16", "HPV16", "HPV16", "HPV16", "HPV16", "HPV16", 
"HPV16", "HPV33"), HPVseq_s = c("HPV16", "HPV53", "HPV16", "HPV16", 
"HPV16", "HPV16", "HPV16", "HPV16", "HPV16", "na"), HPVdPCR_p = c("HPV16", 
"HPV16", "na", "HPV16", "HPV16", "HPV16", "HPV16", "HPV16", "HPV16", 
"HPV33"), HPVdPCR_s = c("HPV16", "HPV16", "HPV16", "HPV16", "HPV16", 
"HPV16", "HPV16", "na", "HPV16", "na")), row.names = c(NA, -10L
), class = c("tbl_df", "tbl", "data.frame"))

im new at this, help would be appreciated!

I am trying to create a circle packing figure, and keep getting the following error message:

"Error in graph_from_data_frame(edges, vertices = vertices) : 
 the data frame should contain at least two columns"

I am trying to create a circles for the HPV variants that exist in HPVseq_p and then subcircles for those that exist in HPVseq_s. (ie a big circle for HPV16 that then contains the various HPV variants inside it for HPVseq_s (HPV16, HPV53)

my code is below:

library(ggraph)
library(igraph)
library(tidyverse)
library(viridis)    
edges <- HPV_subtypes$HPVseq_p
vertices <- HPV_subtypes$HPVseq_s
mygraph <- graph_from_data_frame(edges, vertices=vertices)`

dput(mydata_compressed)
structure(list(Sample = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), HPVseq_p = c("HPV16", 
"HPV16", "HPV16", "HPV16", "HPV16", "HPV16", "HPV16", "HPV16", 
"HPV16", "HPV33"), HPVseq_s = c("HPV16", "HPV53", "HPV16", "HPV16", 
"HPV16", "HPV16", "HPV16", "HPV16", "HPV16", "na"), HPVdPCR_p = c("HPV16", 
"HPV16", "na", "HPV16", "HPV16", "HPV16", "HPV16", "HPV16", "HPV16", 
"HPV33"), HPVdPCR_s = c("HPV16", "HPV16", "HPV16", "HPV16", "HPV16", 
"HPV16", "HPV16", "na", "HPV16", "na")), row.names = c(NA, -10L
), class = c("tbl_df", "tbl", "data.frame"))

im new at this, help would be appreciated!

Share Improve this question asked Mar 14 at 6:30 peaches523peaches523 12 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

I don´t know what is contained in your HPV_subtypes object, but if it is the tibble that can be created from the code below, then you´re passing a vector to the d argument in graph_from_data_frame . Instead you need to pass a dataframe with two columns (the first two in your dataframe), usually named from and to, which specify the association between your components in the dataframe. The remaining columns are regarded as edge attributes, if the vertices argument is NULL , which is the default. Have a look at the example from the ?graph_from_data_frame help page.

What do you want to achieve with this code? is it just for visualization, or do you want to use this graph for computation purposes?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744670637a4587019.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信