[英]tkplot in html with knitr
I am attempting to include a tkplot
from the igraph
package inside an HTML (knit from Rmd) document via the knitr
package. 我试图通过
knitr
包将igraph
包中的tkplot
包含在HTML(从Rmd编织)的HTML文档中。 I asked a very similar question about latex (which should be more difficult) here . 我问了一下乳胶中的非常类似的问题(这应该是比较困难) 这里 。 Yihui answered but I can't transfer that hook and learning to this situation.
Yihui回答了,但是我无法转移这个钩子并学习这种情况。 How can I embed the following
tkplot
in an HTML document using an Rmd file in knitr? 如何使用knitr中的Rmd文件将以下
tkplot
嵌入HTML文档中?
```{r setup, include=FALSE}
library(igraph)
library(tcltk)
```
```{r}
edges <- structure(c("A", "B", "C", "D", "E", "F", "G", "H", "I", "J",
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "A", "B", "C",
"D", "E", "F", "G", "H", "I", "J", "E", "G", "G", "F", "H", "G",
"D", "J", "J", "D", "B", "C", "D", "I", "I", "H", "A", "B", "G",
"I", "F", "D", "F", "J", "D", "B", "E", "E", "A", "E"), .Dim = c(30L,
2L), .Dimnames = list(NULL, c("person", "choice")))
g <- graph.data.frame(edges, directed=TRUE)
tkplot(g)
```
Less attractive but following Yihui's advice: 吸引力较小,但遵循宜辉的建议:
```{r setup, include=FALSE}
library(igraph)
library(rgl)
knit_hooks$set(
webgl = hook_webgl
)
```
```{r, webgl=TRUE, fig.width=12, fig.height=12}
edges <- structure(c("A", "B", "C", "D", "E", "F", "G", "H", "I", "J",
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "A", "B", "C",
"D", "E", "F", "G", "H", "I", "J", "E", "G", "G", "F", "H", "G",
"D", "J", "J", "D", "B", "C", "D", "I", "I", "H", "A", "B", "G",
"I", "F", "D", "F", "J", "D", "B", "E", "E", "A", "E"), .Dim = c(30L,
2L), .Dimnames = list(NULL, c("person", "choice")))
g <- graph.data.frame(edges, directed=TRUE)
rglplot(g)
```
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.