标签: diagrammer

如何通过DiagrammeR在美人鱼(甘特)中获得超过4种颜色?

我必须每天生成一个甘特图.我的想法是使用R的DiagrammeR包中包含的美人鱼api.

我的数据总是具有相同的结构,因此,我创建了一个非常原始的解析器,它包含在可重现的示例中.

我面临的问题是,在4个部分后,样式从零开始:

rect.section.section0
rect.section.section1
rect.section.section2
rect.section.section3
rect.section.section0
Run Code Online (Sandbox Code Playgroud)

我可以改变rect.section.sectionx.css的颜色,但我不能添加新颜色.

有没有办法改变/个性化该部分的颜色/样式?

我可R重复的例子:

library(DiagrammeR)
library(htmltools)

fromdftogantt<-function(df,Title="Proba",filename="proba.html"){
  txt<-paste("gantt","dateFormat  YYYY-MM-DD",paste("title",Title),"",sep="\n")
  for(i in unique(df$section)){
    txt<-paste(txt,paste("section",i),sep="\n")
    for(j in which(df$section==i)){

      txt<-paste(txt,paste0(df$name[j],":",df$status[j],",",
                            df$fecini[j],",",
                            df$fecfin[j]),sep="\n")
    }
    txt<-paste0(txt,"\n")
  }
  m<-mermaid(txt)
  m$x$config = list(ganttConfig = list(
    axisFormatter = list(list(
      "%m-%Y" 
      ,htmlwidgets::JS(
        'function(d){ return d.getDate() == 1 }' 
      )
    ))
  ))
  save_html(as.tags(m),file=filename)
}

df<-data.frame(section=letters[1:6],name=paste("Name",1:6),
               status=rep("active",6),
               fecini=as.Date(c("2015-02-03","2015-03-05","2015-04-07",
                                "2015-02-03","2015-03-05","2015-04-07")),
               fecfin=as.Date(c("2015-06-01","2015-04-30","2015-12-31",
                                "2015-06-01","2015-04-30","2015-12-31")),
               stringsAsFactors = FALSE)

fromdftogantt(df,Title="Proba",filename="proba.html")
Run Code Online (Sandbox Code Playgroud)

r mermaid diagrammer

13
推荐指数
1
解决办法
834
查看次数

DiagrammeR美人鱼:rmarkdown ioslides的结果不一致

我有一个rmarkdown演示文稿(ioslides)有3张幻灯片,流程图在DiagrammeR美人鱼中工作.保存为.Rmd的以下文件可以重现该示例(至少在我的机器中,希望您也是如此):

---
title: "Untitled"
author: "author"
date: "28 de enero de 2018"
output: ioslides_presentation
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)

require(DiagrammeR)
```

## DiagrammeR's mermaid

It's not producing consistent results in slides when using line breaks.

```{r flow}
mermaid("
  graph LR
    C(CLIENTES <br>Clients) --> D[Doctors]
    U(USUARIOS <br>Users <br>Patients <br>Nurses) --> D
    D --> S(SALIDAS <br>Medicines <br>Surgery)
    style C fill: #f5f5dc
    style D fill: #4682b4
    style U fill: #ffe4c4
")
```

## Second attempt

```{r flow2}
mermaid("
  graph …
Run Code Online (Sandbox Code Playgroud)

r r-markdown mermaid diagrammer ioslides

13
推荐指数
1
解决办法
366
查看次数

手动绘制图形

我生成了一个图表:

library(DiagrammeR)
grViz("
digraph boxes_and_circles {

  # a 'graph' statement
  graph [layout = neato, overlap = true, fontsize = 10, outputorder = edgesfirst]

  # several 'node' statements
  node [shape = circle,
  fontname = Helvetica]
  A [pos = '1,1!']; 
  B [pos = '0,2!']; 
  C [pos = '1.5,3!']; 
  D [pos = '2.5,1!']; 
  E [pos = '4,1!']; 
  F [pos = '4,2!']; 
  G [pos = '5,1!']; 
  H [pos = '6,2!']; 
  I [pos = '1.5,-0.1!'];

  # several 'edge' statements
  A->B B->C
  D->E D->F E->F E->G …
Run Code Online (Sandbox Code Playgroud)

plot drawing r figure diagrammer

11
推荐指数
2
解决办法
472
查看次数

在Word文档中使用DiagrammeR(使用rMarkdown生成)

我一直在查看diagrammeR包(http://rich-iannone.github.io/DiagrammeR/)以在rMarkdown中生成图表.这在用HTML呈现文档时效果很好; 现在我的问题是是否有可能将文档输出为MS Word文档?

例如,考虑一下:

---
title: "Test"
author: "Test"
date: "Monday, May 18, 2015"
output: html_document
---

```{r, echo=FALSE, warning=FALSE}
if (!require("DiagrammeR")) library("DiagrammeR")
```

Check out this diagram:

```{r, echo=FALSE, results='asis'}
DiagrammeR::grViz("
      digraph rmarkdown {
      node [shape = box ]
      'A' -> 'B'
      }
      ")
```
Run Code Online (Sandbox Code Playgroud)

使用HTML作为输出格式就像一个魅力.但是,当我切换到MS Word时,我得到的只是:

Error: Functions that produce HTML output found in document targeting docx output.
Please change the output type of this document to HTML.
Run Code Online (Sandbox Code Playgroud)

任何想法,将不胜感激.

非常感谢,Philipp

r r-markdown diagrammer

8
推荐指数
1
解决办法
1246
查看次数

如何在 R 中导出制图师的图像

我正在尝试创建制图仪图形的图像,但它创建的是空白文件。我的数据框:

df <- data.frame(col1 = c( "Cat", "Dog", "Bird"), col2 = c( "Feline", "Canis", "Avis"), stringsAsFactors=FALSE)

其余代码:

png("C:\\tmp\\anim.png")
uniquenodes <- unique(c(df$col1, df$col2))
library(DiagrammeR)
nodes <- create_node_df(n=length(uniquenodes), nodes = seq(uniquenodes), type="number", label=uniquenodes)
edges <- create_edge_df(from=match(df$col1, uniquenodes), to=match(df$col2, uniquenodes), rel="related")

g <- create_graph(nodes_df=nodes, edges_df=edges)
render_graph(g)
dev.off()
Run Code Online (Sandbox Code Playgroud)

r diagrammer

8
推荐指数
3
解决办法
5962
查看次数

DiagrammeR export_graph无效的asm.js

我在R使用中的DiagrammeR's export_graph函数将图形导出为PDF时遇到问题RStudio

下面的示例重现该问题。PDF的生成不一致,因此有时根本没有。

我收到的错误消息是在下面的代码片段中调用export_graph。

我在Windows 10上使用RStudio版本1.1.463和R 3.5.2。

“ \ <” unknown“>”:1919791:无效的asm.js:函数定义与使用不匹配“

library(data.tree)
library(yaml)
library(DiagrammeR)
library(DiagrammeRsvg)

fileName <- system.file("extdata", "jennylind.yaml", package="data.tree")
cat(readChar(fileName, file.info(fileName)$size))
lol <- yaml.load_file(fileName)
jl <- as.Node(lol)
pic <- ToDiagrammeRGraph(jl)
render_graph(pic)
export_graph(pic, "C:/Tmp/plot.pdf", file_type = "pdf")
Run Code Online (Sandbox Code Playgroud)

export r diagrammer

7
推荐指数
0
解决办法
321
查看次数

Rmarkdown 文件中的 DiametermeR/mermaid 流程图,输出格式为 PDF/LaTex

我想在使用 R markdown 生成的 PDF 中包含美人鱼图。

根据这篇文章,mermaid 创建一个 HTML 小部件作为输出。不幸的是,为 xaringan 幻灯片提供的答案不适用于 R markdown 中生成的 PDF。

下面是 Rmd-MWE。任何帮助是极大的赞赏!

---
title: "DiagrammeR: mermaid diagram in Rmd"
output: pdf_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

# Simple mermaid diagram

```{r}
library(DiagrammeR)
mermaid("
graph LR
    A-->B
    ", height = '100%', width = '100%')
```
Run Code Online (Sandbox Code Playgroud)

r r-markdown mermaid diagrammer

7
推荐指数
1
解决办法
3309
查看次数

DiagrammeR:调整节点内的字体大小

我想创建一个流程图DiagrammeRR。在某些节点内,我想减小文本某些部分的字体大小。

考虑以下示例R

library("DiagrammeR")

# Create a node data frame (ndf)
ndf <- create_node_df(n = 4,label = c("aaa", "bbb",
                                      "Same size\nThese letters\nshould be smaller",
                                      "ccc"))

# Create an edge data frame (edf)
edf <- create_edge_df(from = c(1, 2, 3, 3),
                  to = c(4, 3, 1, 4))

# Create a graph with the ndf and edf
graph <- create_graph(nodes_df = ndf,
                      edges_df = edf)

# Print graph
graph %>%
  render_graph()
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

中间节点的字体大小应该部分减小。文本“相同大小”应保持原样。应减小“这些字母应该更小”文本的字体大小。

问题:如何调整节点内某些文本部分的字体大小?

graphics r font-size diagrammer

6
推荐指数
1
解决办法
1238
查看次数

是否可以将箭头从节点绘制为空?

我正在尝试绘制一个简单的图表,DiagrammeR::mermaid它应该如下所示:

 mermaid("
     graph LR
     A(Sample Text)
     -->A
     A-->B
     B-->A 
     B-->
  ")
Run Code Online (Sandbox Code Playgroud)

显然(或不)-->A并且B-->代码不起作用。不可能有箭头从哪里来或从哪里来。

是否有一个简单的解决方法(空白节点?/不可见节点?)

r mermaid diagrammer

6
推荐指数
3
解决办法
1104
查看次数

在 R 中创建组织结构图

我需要用 R 绘制公司的组织结构图。我有一个例子,但我希望箭头离开同一点。

我的期望(来自 PowerPoint):

预期的

我得到了什么(R):

实际的

代码:

grViz("
  digraph {

  graph[splines=ortho, nodesep=1]

  node[shape=box]
  President;Fun1;Fun2;Fun3;

  President->{Fun1,Fun2,Fun3}
  }
  ")
Run Code Online (Sandbox Code Playgroud)

r organizational-chart diagrammer

6
推荐指数
1
解决办法
4863
查看次数