为什么我在ggplot中得到“找不到函数“ theme_rect””?

用户名

我正在尝试这段代码来重新生成此功能,以基于此链接工作来绘制网络,我知道一些功能已弃用,我将opts替换为theme,但出现theme_rect错误

library(network)
library(ggplot2)
library(sna)
library(ergm)
 
 
plotg <- function(net, value=NULL) {
    m <- as.matrix.network.adjacency(net) # get sociomatrix
    # get coordinates from Fruchterman and Reingold's force-directed placement algorithm.
    plotcord <- data.frame(gplot.layout.fruchtermanreingold(m, NULL)) 
    # or get it them from Kamada-Kawai's algorithm: 
    # plotcord <- data.frame(gplot.layout.kamadakawai(m, NULL)) 
    colnames(plotcord) = c("X1","X2")
    edglist <- as.matrix.network.edgelist(net)
    edges <- data.frame(plotcord[edglist[,1],], plotcord[edglist[,2],])
    plotcord$elements <- as.factor(get.vertex.attribute(net, "elements"))
    colnames(edges) <-  c("X1","Y1","X2","Y2")
    edges$midX  <- (edges$X1 + edges$X2) / 2
    edges$midY  <- (edges$Y1 + edges$Y2) / 2
    pnet <- ggplot()  + 
            geom_segment(aes(x=X1, y=Y1, xend = X2, yend = Y2), 
                data=edges, size = 0.5, colour="grey") +
            geom_point(aes(X1, X2,colour=elements), data=plotcord) +
            scale_colour_brewer(palette="Set1") +
            scale_x_continuous(breaks = NA) + scale_y_continuous(breaks = NA) +
            # discard default grid + titles in ggplot2 
            theme(panel.background = theme_minimal()) + theme(legend.position="none")+
            theme(axis.title.x = theme_minimal(), axis.title.y = theme_minimal()) +
            theme( legend.background = theme_rect(colour = NA)) + 
            theme(panel.background = theme_rect(fill = "white", colour = NA)) + 
            theme(panel.grid.minor = theme_minimal(), panel.grid.major = theme_minimal())
    return(print(pnet))
}
 
 
g <- network(150, directed=FALSE, density=0.03)
classes <- rbinom(150,1,0.5) + rbinom(150,1,0.5) + rbinom(150,1,0.5)
set.vertex.attribute(g, "elements", classes)
 
plotg(g)
jared_mamrot

也许您可以将“主题”部分重写为如下形式:

library(network)
library(ggplot2)
library(sna)
library(ergm)
 
 
plotg <- function(net, value=NULL) {
    m <- as.matrix.network.adjacency(net) # get sociomatrix
    # get coordinates from Fruchterman and Reingold's force-directed placement algorithm.
    plotcord <- data.frame(gplot.layout.fruchtermanreingold(m, NULL)) 
    # or get it them from Kamada-Kawai's algorithm: 
    # plotcord <- data.frame(gplot.layout.kamadakawai(m, NULL)) 
    colnames(plotcord) = c("X1","X2")
    edglist <- as.matrix.network.edgelist(net)
    edges <- data.frame(plotcord[edglist[,1],], plotcord[edglist[,2],])
    plotcord$elements <- as.factor(get.vertex.attribute(net, "elements"))
    colnames(edges) <-  c("X1","Y1","X2","Y2")
    edges$midX  <- (edges$X1 + edges$X2) / 2
    edges$midY  <- (edges$Y1 + edges$Y2) / 2
    pnet <- ggplot()  + 
            geom_segment(aes(x=X1, y=Y1, xend = X2, yend = Y2), 
                data=edges, size = 0.5, colour="grey") +
            geom_point(aes(X1, X2,colour=elements), data=plotcord) +
            scale_colour_brewer(palette="Set1") +
            scale_x_continuous(breaks = NULL) + scale_y_continuous(breaks = NULL) +
            # discard default grid + titles in ggplot2 
            theme_minimal() + theme(legend.position="none")+
            theme(legend.background = element_rect(colour = NA)) + 
            theme(panel.background = element_rect(fill = "white", colour = NA))
    return(print(pnet))
}
 
 
g <- network(150, directed=FALSE, density=0.03)
classes <- rbinom(150,1,0.5) + rbinom(150,1,0.5) + rbinom(150,1,0.5)
set.vertex.attribute(g, "elements", classes)
 
plotg(g)

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

为什么我在 gapminder 代码中找不到函数“%>%”

来自分类Dev

为什么我得到“找不到匹配的子程序”。错误?

来自分类Dev

为什么我得到变量找不到错误?

来自分类Dev

我为什么得到(系统找不到指定的路径)

来自分类Dev

为什么在XCode中得到“找不到-lPods的库”

来自分类Dev

为什么我在ggplot中得到这些奇怪的y标签?

来自分类Dev

为什么我得到“找不到模块”我已经尝试了很多解决方案

来自分类Dev

为什么我得到“ ld:找不到体系结构x86_64的符号”

来自分类Dev

为什么我得到这个/ bin / sh:1:^ Mno:找不到错误

来自分类Dev

为什么我在Golang的Date函数中得到错误答案

来自分类Dev

为什么我在函数中得到错误的父节点?

来自分类Dev

为什么我在下面的函数中得到unboundLocalError?

来自分类Dev

为什么我得到一个“在实体类上找不到属性节点……绑定构造函数参数!” 使用Spring Data MongoDB

来自分类Dev

为什么在cppreference中找不到random()函数,但在Linux手册页中却找不到?

来自分类Dev

为什么我的sed搜索在字段中找不到alpha?

来自分类Dev

为什么我在文件中找不到文件但在phonegap中找不到异常

来自分类Dev

为什么我从 print(same(p) 函数中得到 False?我应该得到 True

来自分类Dev

为什么仅在带有Procfile的目录中得到“ foreman:找不到命令”?

来自分类Dev

为什么eval()找不到函数?

来自分类Dev

当我使用rustc进行编译时,为什么会在Cargo.toml中得到列出为依赖项的“找不到板条箱”的信息?

来自分类Dev

为什么我得到无效的命令名称“。!canvas”?我找不到任何可行的解决方案

来自分类Dev

为什么找不到我的功能?

来自分类Dev

为什么找不到我的ViewModel?

来自分类Dev

找不到我的.plist,为什么?

来自分类Dev

为什么找不到我的功能?

来自分类Dev

为什么我的脚本找不到文件?

来自分类Dev

为什么找不到我的桥?

来自分类Dev

为什么我找不到 EvernoteAPI?

来自分类Dev

为什么我找不到窗口?

Related 相关文章

  1. 1

    为什么我在 gapminder 代码中找不到函数“%>%”

  2. 2

    为什么我得到“找不到匹配的子程序”。错误?

  3. 3

    为什么我得到变量找不到错误?

  4. 4

    我为什么得到(系统找不到指定的路径)

  5. 5

    为什么在XCode中得到“找不到-lPods的库”

  6. 6

    为什么我在ggplot中得到这些奇怪的y标签?

  7. 7

    为什么我得到“找不到模块”我已经尝试了很多解决方案

  8. 8

    为什么我得到“ ld:找不到体系结构x86_64的符号”

  9. 9

    为什么我得到这个/ bin / sh:1:^ Mno:找不到错误

  10. 10

    为什么我在Golang的Date函数中得到错误答案

  11. 11

    为什么我在函数中得到错误的父节点?

  12. 12

    为什么我在下面的函数中得到unboundLocalError?

  13. 13

    为什么我得到一个“在实体类上找不到属性节点……绑定构造函数参数!” 使用Spring Data MongoDB

  14. 14

    为什么在cppreference中找不到random()函数,但在Linux手册页中却找不到?

  15. 15

    为什么我的sed搜索在字段中找不到alpha?

  16. 16

    为什么我在文件中找不到文件但在phonegap中找不到异常

  17. 17

    为什么我从 print(same(p) 函数中得到 False?我应该得到 True

  18. 18

    为什么仅在带有Procfile的目录中得到“ foreman:找不到命令”?

  19. 19

    为什么eval()找不到函数?

  20. 20

    当我使用rustc进行编译时,为什么会在Cargo.toml中得到列出为依赖项的“找不到板条箱”的信息?

  21. 21

    为什么我得到无效的命令名称“。!canvas”?我找不到任何可行的解决方案

  22. 22

    为什么找不到我的功能?

  23. 23

    为什么找不到我的ViewModel?

  24. 24

    找不到我的.plist,为什么?

  25. 25

    为什么找不到我的功能?

  26. 26

    为什么我的脚本找不到文件?

  27. 27

    为什么找不到我的桥?

  28. 28

    为什么我找不到 EvernoteAPI?

  29. 29

    为什么我找不到窗口?

热门标签

归档