A quick question regarding using DiagrammeR package. I'm trying to create a diagram and output it as an image in png format or use it to generate diagram directly in Rmarkdown. However, the output always has original DiagrammeR codes. I tried set echo=F in Rmarkdown, but still have no luck. Are there other more straightforward methods to get the diagram out?
My r markdown codes:
covid <- "graph LR;A(GPS data)-->C{Analytic data};
B[Weather data]-->C{Analytic data};
D[Masking mandatory/compliance]-->C{Analytic data};
E[Demographics]-->C{Analytic data};
F[Covid-testing result]-->C{Analytic data};
G[Covid confirmed cases]-->C{Analytic data};
C{Analytic data}-->M[Modeling];
M[Modeling]-->V[Data visualization]
style A fill:#E5E25F; style B fill:#87AB51; style C fill:#3C8937;
style D fill:#23772C; style E fill:#B6E6E6;
style F fill:#E5E25F; style G fill:#87AB51; style M fill:#3C8937;
style V fill:#23772C; "
DiagrammeR::mermaid(covid)
Any suggest on how to achieve this goal? Thanks!
CodePudding user response:
The format is important for DiagrammeR
, you should not use the ";" signs in your code. You can use the following code:
---
title: "Untitled"
author: "Author"
date: "2022-07-22"
output: html_document
---
```{r, echo=FALSE}
library(DiagrammeR)
covid <- "graph LR;
A(GPS data)-->C{Analytic data}
B[Weather data]-->C{Analytic data}
D[Masking mandatory/compliance]-->C{Analytic data}
E[Demographics]-->C{Analytic data}
F[Covid-testing result]-->C{Analytic data}
G[Covid confirmed cases]-->C{Analytic data}
C{Analytic data}-->M[Modeling]
M[Modeling]-->V[Data visualization]
style A fill:#E5E25F style B fill:#87AB51 style C fill:#3C8937;
style D fill:#23772C style E fill:#B6E6E6
style F fill:#E5E25F style G fill:#87AB51 style M fill:#3C8937;
style V fill:#23772C "
mermaid(covid)
```
Output: