Skip to content

Instantly share code, notes, and snippets.

@mkcor
Last active May 3, 2017 20:13
Show Gist options
  • Save mkcor/1ca67262c74c590bd6e9 to your computer and use it in GitHub Desktop.
Save mkcor/1ca67262c74c590bd6e9 to your computer and use it in GitHub Desktop.
Get started with plotly and knitr!
---
title: "knitr_session"
author: "Marianne Corvellec"
date: '2014-11-14'
output: html_document
---
(View source here: https://gist.github.com/mkcor/1ca67262c74c590bd6e9)
This is an R Markdown document. Markdown is a simple formatting syntax for
authoring documents. For more details on using R Markdown see
<http://rmarkdown.rstudio.com>.
You can embed an R code chunk like this:
```{r}
summary(cars)
```
You can also embed plots, for example:
```{r}
library(plotly)
gg <- ggplot(cars) + geom_point(aes(speed, dist))
gg
```
```{r, plotly=TRUE}
py <- plotly()
py$ggplotly(gg, session="knitr", kwargs=list(filename="cars_knitr",
fileopt="overwrite"))
```
You can embed a static plot using Markdown syntax:
![cars_plot](https://plot.ly/~marianne2/167.png)
Notice that we simply appended a supported extension (.png) to the URL where the
plotly plot lives.
You can also use HTML syntax to embed iframes:
<iframe scrolling='no' seamless='seamless' style='border:none'
src='https://plot.ly/~MattSundquist/2509' width='800' height='500'></iframe>
@MaxGhenis
Copy link

plotly() now seems to be deprecated. Lines 30-31 can be replaced with just ggplotly(...)

@MaxGhenis
Copy link

Actually plotly=T and the other arguments to ggplotly are also now unnecessary. The following works as a replacement for lines 29-33:

```{r}
ggplotly(gg)
```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment