English 中文(简体)
如何使用最合适的方法在 R 中绘制一个简单的术语树
原标题:How to plot a simple terminology tree in R using the most suitable approach
  • 时间:2012-05-25 17:16:04
  •  标签:
  • r
  • tree
  • plot

我需要在R中绘制这个结构:

(1000) Diseases of the genitourinary system 
    (1580) Nephritis, nephrotic syndrome, and nephrosis 
        (580) Acute glomerulonephritis
            (580.9) Glomerulonephritis, acute, unspec.
        (581) Nephrotic syndrome
            (581.9) Nephrotic syndrome, unspec.
        (582) Chronic glomerulonephritis
            (582.9) Glomerulonephritis, chronic, unspec.
        (583) Nephritis and nephropathy, not specified as acute or chronic
        (584) Acute renal failure
            (584.5) Renal failure, acute w/ tubular necrosis

as a nice jpg/pdf/(or other) which will have nodes, connections and labels using R of the structure above. I looked at libraries which require GrafViz installed and had no luck so native solution (e.g., using ggplot2) would be best. I was not able to put together the code using igraph. I am also new to graphics in R with no textbook based foundation. Any hints or advice would be appreciated.

上述结构仅举一例。 其它结构可能拥有50+的概念, 可以作为非常大的 PDF/ poser 绘制和打印。 此图将是静态的( 没有使用鼠标与其互动 ) 。

最佳回答

这是对答案的一种努力。它接近于你需要的东西,最后的结果是这样的:

"https://i.sstatic.net/EBEEyq.png" alt="名词树"/>

我在igraph 中做了这个,代码使用您描述的数据类型的模拟。

library("igraph")

vertex.df <- read.table(text = "id    code  name
0   1000     Diseases of the genitourinary system  
1   1580     Nephritis, nephrotic syndrome, and nephrosis  
2   580  Acute glomerulonephritis 
3   580.9    Glomerulonephritis, acute, unspec. 
4   581  Nephrotic syndrome 
5   581.9    Nephrotic syndrome, unspec. 
6   582  Chronic glomerulonephritis 
7   582.9    Glomerulonephritis, chronic, unspec. 
8   583  Nephritis and nephropathy, not specified as acute or chronic 
9   584  Acute renal failure 
10  584.5    Renal failure, acute w/ tubular necrosis ",
                        header = TRUE,
                        stringsAsFactor = FALSE)

vertex.df$code <- as.character( vertex.df$code )

edge.df <- read.table(text = "from    to
0    1
1   2
1   4
1   6
1   8
1   9
2   3
4   5
6   7
9   10",
                      header = TRUE)

edges <- matrix(c(edge.df$from, edge.df$to), nc=2)

g <- graph.empty()
g <- add.vertices(g, nrow(vertex.df),
                  id=vertex.df$id, 
                  code=vertex.df$code, 
                  name=vertex.df$name)
g <- add.edges(g, t(edges))


plot(g, 
     layout = layout.kamada.kawai,
     vertex.label = V(g)$code,
     vertex.size = 35,
     vertex.color = "white",
     vertex.label.family = "sans")

我使用 ICD 代码作为顶点标签。 这是因为在此刻度绘制时, 疾病名称的长文本看起来不整齐 。

绘制时, 您可以将 < code> vertex. label 参数更改为 < code> V(g)$name , 如果您想要疾病名称, 而不是 ICD 代码。 我怀疑, 如果您打印到一个大的 pdf 并删除顶点外观, 您可能会得到一棵好看的树。 请查看 < code>? igraph. plotting , 了解您可以更改的参数的细节 。

我希望这能让你的实验更进一步

问题回答

暂无回答




相关问题
How to plot fitted model over observed time series

This is a really really simple question to which I seem to be entirely unable to get a solution. I would like to do a scatter plot of an observed time series in R, and over this I want to plot the ...

REvolution for R

since the latest Ubuntu release (karmic koala), I noticed that the internal R package advertises on start-up the REvolution package. It seems to be a library collection for high-performance matrix ...

R - capturing elements of R output into text files

I am trying to run an analysis by invoking R through the command line as follows: R --no-save < SampleProgram.R > SampleProgram.opt For example, consider the simple R program below: mydata =...

R statistical package: wrapping GOFrame objects

I m trying to generate GOFrame objects to generate a gene ontology mapping in R for unsupported organisms (see http://www.bioconductor.org/packages/release/bioc/vignettes/GOstats/inst/doc/...

Changing the order of dodged bars in ggplot2 barplot

I have a dataframe df.all and I m plotting it in a bar plot with ggplot2 using the code below. I d like to make it so that the order of the dodged bars is flipped. That is, so that the bars labeled "...

Strange error when using sparse matrices and glmnet

I m getting a weird error when training a glmnet regression. invalid class "dgCMatrix" object: length(Dimnames[[2]]) must match Dim[2] It only happens occasionally, and perhaps only under larger ...

Generating non-duplicate combination pairs in R

Sorry for the non-descriptive title but I don t know whether there s a word for what I m trying to achieve. Let s assume that I have a list of names of different classes like c( 1 , 2 , 3 , 4 ) ...

Per panel smoothing in ggplot2

I m plotting a group of curves, using facet in ggplot2. I d like to have a smoother applied to plots where there are enough points to smooth, but not on plots with very few points. In particular I d ...

热门标签