R의 네트워크 플롯에 텍스트를 추가하려면 어떻게해야합니까?

Nclaidiere

이 패키지 networkDynamic사용하여 진화하는 두 개의 네트워크를 시각화하고 있으며 각 네트워크 가까이에 간단한 범례 (텍스트 몇 단어)를 추가하고 싶습니다. 이 방법을 찾을 수 없습니다.

에서 networkDynamic패키지 함수 render.animation사용 plot.network(패키지로부터는 network) 각 프레임을 렌더링하기 위해 다음 애니메이션으로 다른 프레임을 컴파일한다.

plot.network인수로 전달 될 수있는 render.animation문제가 보인다 생성 플롯에 텍스트를 추가로 귀결 있도록, plot.network하지만 지정된 좌표에 텍스트를 추가하는 방법이있을 것 같지 않습니다.

정상 plot에서는 text함수를 사용 하지만이 함수를 plot.network인수 에 포함하는 방법이 있습니까?

피에르 라포 인 테

render.animationndtv패키지 의 기능입니다 . render.animation2기반으로 사용자 지정 함수 를 만들어야합니다 render.animation. 다음 함수에서는 함수에 추가 행을 추가 render.animation합니다. mtextplot.network통화 후에 추가 합니다 (끝에서 약 20 줄 참조). text대신으로 변경할 수 있습니다 mtext.

render.animation2 <- function (net, render.par = list(tween.frames = 10, show.time = TRUE,
    show.stats = NULL, extraPlotCmds = NULL, initial.coords = 0),
    plot.par = list(bg = "white"), ani.options = list(interval = 0.1),
    render.cache = c("plot.list", "none"), verbose = TRUE, ...)
{
    if (!is.network(net)) {
        stop("render.animation requires the first argument to be a network object")
    }
    if (is.null(render.par)) {
        stop("render.animation is missing the 'render.par' argument (a list of rendering parameters).")
    }
    if (is.null(render.par$tween.frames)) {
        render.par$tween.frames <- 10
    }
    if (is.null(render.par$show.time)) {
        render.par$show.time <- TRUE
    }
    if (is.null(render.par$initial.coords)) {
        render.par$initial.coords <- matrix(0, ncol = 2, nrow = network.size(net))
    }
    if (!all(c("animation.x.active", "animation.y.active") %in%
        list.vertex.attributes(net))) {
        net <- compute.animation(net, verbose = verbose)
    }
    externalDevice <- FALSE
    doRStudioHack <- TRUE
    if (!is.null(render.par$do_RStudio_plot_hack)) {
        doRStudioHack <- render.par$do_RStudio_plot_hack
    }
    if (!is.function(options()$device)) {
        if (names(dev.cur()) == "RStudioGD" & doRStudioHack) {
            message("RStudio's graphics device is not well supported by ndtv, attempting to open another type of plot window")
            if (.Platform$OS.type == "windows") {
                windows()
            }
            else if (length(grep(R.version$platform, pattern = "apple")) >
                0) {
                quartz()
            }
            else {
                x11()
            }
            externalDevice <- TRUE
        }
    }
    if (par("bg") == "transparent" & is.null(plot.par$bg)) {
        plot.par$bg <- "white"
    }
    origPar <- par(plot.par)
    oopts <- ani.options(ani.options)
    slice.par <- get.network.attribute(net, "slice.par")
    if (is.null(slice.par)) {
        stop("render.animation can not locate the 'slice.par' list of parameters in the input network object")
    }
    render.cache <- match.arg(render.cache)
    plot_params <- list(...)
    if (is.null(plot_params$label)) {
        plot_params$label <- function(slice) {
            network.vertex.names(slice)
        }
    }
    if (is.null(plot_params$xlab) & render.par$show.time) {
        plot_params$xlab <- function(onset, terminus) {
            ifelse(onset == terminus, paste("t=", onset, sep = ""),
                paste("t=", onset, "-", terminus, sep = ""))
        }
    }
    if (!is.null(render.par$show.stats) && render.par$show.stats !=
        FALSE) {
        if (render.par$show.time) {
            plot_params$xlab <- eval(parse(text = paste("function(slice,onset,terminus){stats<-summary.statistics.network(slice",
                render.par$show.stats, ")\n return(paste('t=',onset,'-',terminus,' ',paste(rbind(names(stats),stats),collapse=':'),sep='')) }",
                sep = "")))
        }
        else {
            plot_params$xlab <- eval(parse(text = paste("function(slice){stats<-summary.statistics.network(slice",
                render.par$show.stats, ")\n return(paste(rbind(names(stats),stats),collapse=':')) }",
                sep = "")))
        }
    }
    if (is.null(plot_params$jitter)) {
        plot_params$jitter <- FALSE
    }
    interp.fun <- coord.interp.smoothstep
    starts <- seq(from = slice.par$start, to = slice.par$end,
        by = slice.par$interval)
    ends <- seq(from = slice.par$start + slice.par$aggregate.dur,
        to = slice.par$end + slice.par$aggregate.dur, by = slice.par$interval)
    xmin <- aggregate.vertex.attribute.active(net, "animation.x",
        min)
    xmax <- aggregate.vertex.attribute.active(net, "animation.x",
        max)
    ymin <- aggregate.vertex.attribute.active(net, "animation.y",
        min)
    ymax <- aggregate.vertex.attribute.active(net, "animation.y",
        max)
    if (is.null(plot_params$xlim)) {
        if (xmin == xmax) {
            xmax <- xmin + 1
            xmin <- xmin - 1
        }
        plot_params$xlim <- c(xmin, xmax)
    }
    if (is.null(plot_params$ylim)) {
        if (ymin == ymax) {
            ymax <- ymin + 1
            ymin <- ymin - 1
        }
        plot_params$ylim <- c(ymin, ymax)
    }
    if (is.numeric(render.par$initial.coords)) {
        coords <- matrix(render.par$initial.coords, ncol = 2,
            nrow = network.size(net))
    }
    slice <- network.collapse(net, starts[1], ends[1], rule = slice.par$rule,
        rm.time.info = FALSE)
    activev <- is.active(net, starts[1], ends[1], v = seq_len(network.size(net)),
        rule = if (slice.par$rule != "all") {
            "any"
        })
    if (length(slice) > 0 & network.size(slice) > 0) {
        coords[activev, 1] <- get.vertex.attribute(slice, "animation.x")
        coords[activev, 2] <- get.vertex.attribute(slice, "animation.y")
    }
    coords2 <- coords
    if (render.cache == "plot.list") {
        ani.record(reset = TRUE)
    }
    for (s in 1:length(starts)) {
        if (verbose) {
            print(paste("rendering", render.par$tween.frames,
                "frames for slice", s - 1))
        }
        slice <- network.collapse(net, starts[s], ends[s], rule = slice.par$rule,
            rm.time.info = FALSE)
        activev <- is.active(net, starts[s], ends[s], v = seq_len(network.size(net)),
            rule = if (slice.par$rule != "all") {
                "any"
            })
        if (length(slice) > 0 & network.size(slice) > 0) {
            evald_params <- .evaluate_plot_params(plot_params = plot_params,
                net = net, slice = slice, s = s, onset = starts[s],
                terminus = ends[s])
            for (t in 1:render.par$tween.frames) {
                coords2[activev, 1] <- get.vertex.attribute(slice,
                  "animation.x")
                coords2[activev, 2] <- get.vertex.attribute(slice,
                  "animation.y")
                tweenCoords <- interp.fun(coords, coords2, t,
                  render.par$tween.frames)
                plot_args <- list(x = slice, coord = tweenCoords[activev,
                  , drop = FALSE])
                plot_args <- c(plot_args, evald_params)
                do.call(plot.network, plot_args)
                mtext("my text\n on two lines", side = 3) #my.legend
                if (!is.null(render.par$extraPlotCmds)) {
                  eval(render.par$extraPlotCmds)
                }
                if (render.cache == "plot.list") {
                  ani.record()
                }
            }
            coords <- coords2
        }
        else {
            evald_params <- .evaluate_plot_params(plot_params = plot_params,
                net = net, slice = slice, s = s, onset = starts[s],
                terminus = ends[s])
            if (render.par$show.time) {
                xlab <- evald_params$xlab
            }
            else {
                xlab <- NULL
            }
            singlenet <- network.initialize(1)
            for (t in 1:render.par$tween.frames) {
                plot.network(singlenet, vertex.cex = 0, xlab = xlab)
                if (!is.null(render.par$extraPlotCmds)) {
                  eval(render.par$extraPlotCmds)
                }
                if (render.cache == "plot.list") {
                  ani.record()
                }
            }
        }
    }
    par(origPar)
    if (externalDevice) {
        dev.off()
    }
}

그런 다음 새 함수 render.animation2ndtv네임 스페이스 에 할당하는 것이 중요 합니다. 그렇지 않으면 render.animation자체 네임 스페이스에서만 찾을 수있는 함수를 참조하기 때문에 충돌이 발생 합니다.

environment(render.animation2) <- asNamespace('ndtv')
environment(render.animation)  #<environment: namespace:ndtv>
environment(render.animation2) #<environment: namespace:ndtv>

render.animation2,를 사용 하면 애니메이션의 각 슬라이드에 범례가 인쇄됩니다.

require(ndtv)
triangle <- network.initialize(3) # create a toy network
add.edge(triangle,1,2)
# add an edge between vertices 1 and 2
add.edge(triangle,2,3)
# add a more edges
activate.edges(triangle,at=1) # turn on all edges at time 1 only
activate.edges(triangle,onset=2, terminus=3,
e=get.edgeIDs(triangle,v=1,alter=2))
add.edges.active(triangle,onset=4, length=2,tail=3,head=1)
render.animation2(triangle) #custom function
ani.replay()

애니메이션의 마지막 슬라이드는 다음과 같습니다. 여기에 이미지 설명 입력

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Mapbox GL의 geojson 레이어에서 텍스트 필드를 추가하려면 어떻게해야합니까?

분류에서Dev

macOS에서 Ubiquiti의 UniFi 네트워크 컨트롤러를 실행하려면 어떻게해야합니까?

분류에서Dev

bash의 특정 줄에 긴 텍스트를 추가하려면 어떻게해야합니까?

분류에서Dev

GSM 네트워크에서 회의 통화를 시작하려면 어떻게해야합니까?

분류에서Dev

ContentPlaceHolder에 긴 텍스트를 추가하려면 어떻게해야합니까?

분류에서Dev

변수에 텍스트를 추가하려면 어떻게해야합니까?

분류에서Dev

내 meteor 앱을 로컬 네트워크의 Ubuntu 서버에 배포하려면 어떻게해야합니까?

분류에서Dev

네트워크의 다른 노드에 다른 색상을 할당하려면 어떻게해야합니까?

분류에서Dev

AS3의 텍스트 입력란에 스타일을 추가하려면 어떻게해야합니까?

분류에서Dev

R에서 왼쪽 괄호까지 모든 텍스트를 추출하려면 어떻게해야합니까?

분류에서Dev

홈 네트워크를 빌딩 네트워크에서 분리하려면 어떻게해야합니까?

분류에서Dev

히스토그램 플롯에 카운트를 추가하려면 어떻게해야합니까?

분류에서Dev

히스토그램 플롯에 카운트를 추가하려면 어떻게해야합니까?

분류에서Dev

콤보 상자의 값을 텍스트 영역에 추가하려면 어떻게해야합니까?

분류에서Dev

SQLite 쿼리의 텍스트 필드에 WHERE 조건을 추가하려면 어떻게해야합니까?

분류에서Dev

textBox에서 텍스트를 구문 분석하고 텍스트의 각 부분을 문자열 변수에 추가하려면 어떻게해야합니까?

분류에서Dev

배치 파일을 사용하여 여러 텍스트 파일의 시작 부분에 텍스트를 추가하려면 어떻게해야합니까?

분류에서Dev

'익명'네트워크 네임 스페이스 내부의 veth 장치를 외부 장치에 연결하려면 어떻게해야합니까?

분류에서Dev

R의 점도표에 두 번째 데이터 세트를 추가하려면 어떻게해야합니까?

분류에서Dev

R의 점도표에 두 번째 데이터 세트를 추가하려면 어떻게해야합니까?

분류에서Dev

WordPress의 자체 플러그인 아래에 사용자 정의 텍스트 필드를 추가하려면 어떻게해야합니까?

분류에서Dev

AntDesign의 Table 구성 요소 내에서 오버플로 텍스트에 줄임표를 추가하려면 어떻게해야합니까?

분류에서Dev

파일의 줄 텍스트를 텍스트 상자에 배치하려면 어떻게해야합니까?

분류에서Dev

텍스트 상자에 텍스트를 추가하려면 어떻게해야합니까?

분류에서Dev

R의 텍스트 데이터에서 "/ url? q ="를 제거하려면 어떻게해야합니까?

분류에서Dev

xamarin.ios에서 이미지의 텍스트를 스크롤하려면 어떻게해야합니까?

분류에서Dev

Vim을 통해 텍스트 문서의 각 줄 끝에 자동 증가 번호를 추가하려면 어떻게해야합니까?

분류에서Dev

CloudFormation 템플릿을 업데이트 할 때 "호환되지 않는 시작 템플릿 : 네트워크 인터페이스의 디바이스 인덱스가 0이어야합니다"를 해결하려면 어떻게해야합니까?

분류에서Dev

같은 행에 3 개의 플롯 게이지 차트를 만들려면 어떻게해야합니까?

Related 관련 기사

  1. 1

    Mapbox GL의 geojson 레이어에서 텍스트 필드를 추가하려면 어떻게해야합니까?

  2. 2

    macOS에서 Ubiquiti의 UniFi 네트워크 컨트롤러를 실행하려면 어떻게해야합니까?

  3. 3

    bash의 특정 줄에 긴 텍스트를 추가하려면 어떻게해야합니까?

  4. 4

    GSM 네트워크에서 회의 통화를 시작하려면 어떻게해야합니까?

  5. 5

    ContentPlaceHolder에 긴 텍스트를 추가하려면 어떻게해야합니까?

  6. 6

    변수에 텍스트를 추가하려면 어떻게해야합니까?

  7. 7

    내 meteor 앱을 로컬 네트워크의 Ubuntu 서버에 배포하려면 어떻게해야합니까?

  8. 8

    네트워크의 다른 노드에 다른 색상을 할당하려면 어떻게해야합니까?

  9. 9

    AS3의 텍스트 입력란에 스타일을 추가하려면 어떻게해야합니까?

  10. 10

    R에서 왼쪽 괄호까지 모든 텍스트를 추출하려면 어떻게해야합니까?

  11. 11

    홈 네트워크를 빌딩 네트워크에서 분리하려면 어떻게해야합니까?

  12. 12

    히스토그램 플롯에 카운트를 추가하려면 어떻게해야합니까?

  13. 13

    히스토그램 플롯에 카운트를 추가하려면 어떻게해야합니까?

  14. 14

    콤보 상자의 값을 텍스트 영역에 추가하려면 어떻게해야합니까?

  15. 15

    SQLite 쿼리의 텍스트 필드에 WHERE 조건을 추가하려면 어떻게해야합니까?

  16. 16

    textBox에서 텍스트를 구문 분석하고 텍스트의 각 부분을 문자열 변수에 추가하려면 어떻게해야합니까?

  17. 17

    배치 파일을 사용하여 여러 텍스트 파일의 시작 부분에 텍스트를 추가하려면 어떻게해야합니까?

  18. 18

    '익명'네트워크 네임 스페이스 내부의 veth 장치를 외부 장치에 연결하려면 어떻게해야합니까?

  19. 19

    R의 점도표에 두 번째 데이터 세트를 추가하려면 어떻게해야합니까?

  20. 20

    R의 점도표에 두 번째 데이터 세트를 추가하려면 어떻게해야합니까?

  21. 21

    WordPress의 자체 플러그인 아래에 사용자 정의 텍스트 필드를 추가하려면 어떻게해야합니까?

  22. 22

    AntDesign의 Table 구성 요소 내에서 오버플로 텍스트에 줄임표를 추가하려면 어떻게해야합니까?

  23. 23

    파일의 줄 텍스트를 텍스트 상자에 배치하려면 어떻게해야합니까?

  24. 24

    텍스트 상자에 텍스트를 추가하려면 어떻게해야합니까?

  25. 25

    R의 텍스트 데이터에서 "/ url? q ="를 제거하려면 어떻게해야합니까?

  26. 26

    xamarin.ios에서 이미지의 텍스트를 스크롤하려면 어떻게해야합니까?

  27. 27

    Vim을 통해 텍스트 문서의 각 줄 끝에 자동 증가 번호를 추가하려면 어떻게해야합니까?

  28. 28

    CloudFormation 템플릿을 업데이트 할 때 "호환되지 않는 시작 템플릿 : 네트워크 인터페이스의 디바이스 인덱스가 0이어야합니다"를 해결하려면 어떻게해야합니까?

  29. 29

    같은 행에 3 개의 플롯 게이지 차트를 만들려면 어떻게해야합니까?

뜨겁다태그

보관