RMarkdown and ggplotly

北慕城南 提交于 2020-05-30 03:52:06

问题


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.

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()

回答1:


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!



来源:https://stackoverflow.com/questions/41819837/rmarkdown-and-ggplotly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!