knitr::opts_chunk$set(echo = TRUE)
library(reticulate)
library(dplyr)

Indicate Specific Conda Environment

reticulate::use_condaenv("~/r-reticulate")

Import Python Packages (will use “~/r-reticulate” as per call to use_condaenv)

import pandas as pd
import seaborn as sb
import matplotlib.pyplot as plt

Look at Flowers with Python

For a quick demo, see: https://medium.com/save-the-data/how-to-use-python-in-r-with-reticulate-and-conda-36685534f06a

data("iris")
iris_df <- iris
iris_dataset = r.iris_df
iris_dataset["Species"].describe()
## count        150
## unique         3
## top       setosa
## freq          50
## Name: Species, dtype: object
plt.clf()
sb.set_style("ticks")
#sb.set_context("paper")

iris_dataset["Species"].describe()
## count        150
## unique         3
## top       setosa
## freq          50
## Name: Species, dtype: object
iris_dataset["Petal.Length"].describe()
## count    150.000000
## mean       3.758000
## std        1.765298
## min        1.000000
## 25%        1.600000
## 50%        4.350000
## 75%        5.100000
## max        6.900000
## Name: Petal.Length, dtype: float64
sb.boxplot(data = iris_dataset, x = "Species", y = "Petal.Length")
plt.show()

plt.clf()
sb.set_style("ticks")
#sb.set_context("paper")

p = sb.pairplot(iris_dataset, hue="Species")
plt.show()

Look at Star Wars with Python

data("starwars")
sw_df <- starwars
names(sw_df)
##  [1] "name"       "height"     "mass"       "hair_color" "skin_color"
##  [6] "eye_color"  "birth_year" "sex"        "gender"     "homeworld" 
## [11] "species"    "films"      "vehicles"   "starships"
sw_dataset = r.sw_df
sw_dataset["gender"].describe()
## count            87
## unique            3
## top       masculine
## freq             66
## Name: gender, dtype: object
plt.clf()
sb.set_style("ticks")
#sb.set_context("paper")

sw_dataset["gender"].describe()
## count            87
## unique            3
## top       masculine
## freq             66
## Name: gender, dtype: object
sw_dataset["mass"].describe()
## count      59.000000
## mean       97.311864
## std       169.457163
## min        15.000000
## 25%        55.600000
## 50%        79.000000
## 75%        84.500000
## max      1358.000000
## Name: mass, dtype: float64
sb.boxplot(data = sw_dataset, x = "gender", y = "mass")
plt.show()

plt.clf()
sb.set_style("ticks")
#sb.set_context("paper")

p2 = sb.pairplot(sw_dataset, hue="gender")
plt.show()