# Hide warnings if there are any
import warnings
warnings.filterwarnings('ignore')
# Load in the r magic
%load_ext rpy2.ipython
# We need ggplot2
%R require(ggplot2)
# Load in the pandas library
import pandas as pd
# Make a pandas DataFrame
df = pd.DataFrame({'Alphabet': ['a', 'b', 'c', 'd','e', 'f', 'g', 'h','i'],
'A': [4, 3, 5, 2, 1, 7, 7, 5, 9],
'B': [0, 4, 3, 6, 7, 10,11, 9, 13],
'C': [1, 2, 3, 1, 2, 3, 1, 2, 3]})
%%R -i df
# Plot the DataFrame df
ggplot(data=df) + geom_point(aes(x=A, y=B, color=Alphabet, size=C))
# Create sample data by randomly selecting 1000 points from normal distribution
import pandas as pd
import numpy as np
data = np.random.randn(5000, 1)
df = pd.DataFrame(data, columns=["value"])
%%R -i df -w 800 -h 480 -u px
# Use magic extension and pass python dataframe created above
library(ggplot2)
ggplot(df) + geom_density(aes(x=value))
%R library(tidyverse)
%%R
ggplot(data= mpg) + geom_point(mapping = aes(x = displ, y = hwy))
from ggplot import diamonds
import pandas as pd
df = pd.DataFrame(diamonds)
%R -i df
%%R
ggplot(df, aes(x=carat, y=price, color=clarity)) + geom_point()
x = np.array([1, 2, 4, 6, 5, 8])
y = np.array([0, 1, 3, 2, 5, 7])
%%R -i x,y -o mycoef,xylm
xylm = lm(y~x)
mycoef = coef(xylm)
par(mfrow = c(2, 2))
plot(xylm)
import rpy2.robjects as ro
print(ro.r('summary(xylm)'))
print(ro.r('ls(xylm)'))
print(ro.r('residuals(xylm)'))