本文介绍了RMarkdown和ggplotly的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望创建一个交互式图形以发送给既没有使用R又没有使用R的同事.我创建的图形包含机密数据.

I am wishing to create an interactive figure to send to a co-worker, who does not have nor use R. The figure that I am creating contains confidential data.

我是使用ggplotly的初学者,并且了解可以在线发布交互式图形,但是,我不希望此图形公开发布.我一直在使用离线绘图版本.我了解可以使用R Markdown编译交互式报告(包括绘图).但是,如果我在R中运行该图并创建一个独立的html文件,该图是否仍会通过我的plotly帐户发布?如果是这样,我该怎么做?

I am a beginner at using ggplotly and understand interactive figures can be posted online, however, I don't wish for this figure to be publicly available. I have been using the offline plotting version. I understand interactive reports, including plotly figures, can be compiled using R Markdown. However, if I run this plot in R and create a standalone html file, will the plot still be posted via my plotly account? If so, how can I go about doing this?

下面是一个我想发送给我的同事的交互式人物的例子,出于示例目的,它使用内置数据集.

Below is an example of the interactive figure I wish to send to my co-worker, using an inbuilt dataset for example purposes.

# Require
library(plotly)
# Create
dsamp <- diamonds[sample(nrow(diamonds), 1000), ]
# Plot
qplot(carat, price, data=dsamp, colour=clarity)
# Call
ggplotly()

推荐答案

如果将文件呈现为html,则只需将其通过电子邮件发送给您的同事,而无需将其托管在任何地方.他们可以从那里选择在其浏览器中打开html文件,该文件仍将具有通过plotly生成的交互式图形.例如,如果我在rmarkdown文档中包含以下代码,则只需按一下rstudio左上角的knit.

If you render the file as html, you can just email it to your coworker without hosting it anywhere. From there they can choose to open the html file in their browser, and it will still have the interactive graph generated through plotly. For example, if I had the following code in an rmarkdown document, I could simply press knit at the top left corner of rstudio.

---
title: "RmarkdownExample"
author: "be_green"
date: "January 24, 2017"
output: html_document
---

Here is the graph I generated. 

```{r setup, message = FALSE, echo = FALSE, warning=FALSE}
# Require
library(plotly)
# Create
dsamp <- diamonds[sample(nrow(diamonds), 1000), ]
# Plot
g <- qplot(carat, price, data=dsamp, colour=clarity)
# Call
ggplotly(g)
```

生成的文件将自动保存在您的工作目录中,您可以将其附加到电子邮件中,或像其他任何文件一样将其保存到共享驱动器中.从那里您的同事可以打开它,并且什么都不会公开!

The file generated will be automatically saved in your working directory, and you can attach it to an email or save it to a shared drive just like any other file. From there your coworker can open it and nothing will be public!

这篇关于RMarkdown和ggplotly的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 03:41