Skip to content

Instantly share code, notes, and snippets.

Created March 28, 2018 09:12
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save CerebralMastication/e8f7ddc02e081741e6eb25ddf2f94ca5 to your computer and use it in GitHub Desktop.
RMarkdown Example using Python and R together
title: "Markdown Y'All"
author: "James Long"
date: "March 27, 2018"
html_document: default
pdf_document: default
word_document: default
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
## Run Some Python
We can use R Markdown to call Python code and return Python plots.
```{python, echo=FALSE}
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
df = pd.DataFrame(np.random.randn(100, 4), columns=list('ABCD'))
#pd.scatter_matrix(df, alpha=0.2, diagonal='kde')
print df.head()
## Grab Python Data Back Into R
Let's use the same data frame from Python and use it in R. To do this
we'll access the special `py` object created by the `reticulate` package.
```{r, echo=FALSE}
ggplot(py$df, aes(A)) +
geom_density() +
xlim(-6, 6)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment