Created
May 2, 2021 17:01
-
-
Save thistleknot/9a043b7caa69db452f1dd57c9ae1feea to your computer and use it in GitHub Desktop.
Graph R in Jupyter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
os.environ['R_HOME'] = '/mnt/distvol/R/4.0.5/lib64/R/' | |
import rpy2.robjects as ro | |
from rpy2.robjects.packages import importr | |
from rpy2.robjects import pandas2ri | |
pandas2ri.activate() | |
k = 4 | |
grdevices = importr('grDevices') | |
grdevices.png(file="kNNdistplot.png", width=512, height=512) | |
ro.r(''' | |
eq <- function(values, k_) { | |
library(dbscan,lib.loc = "/mnt/distvol/R-4.0.5/library") | |
#data <- read.csv("/mnt/distvol/data.csv") | |
kNNdistplot(values,k=k_) | |
} | |
''') | |
r_eq = ro.globalenv['eq'] | |
p=ro.conversion.rpy2py((r_eq(ro.conversion.py2rpy(data),k))) | |
#p = ro.r('eq(1)') # OUTPUTS TO FILE | |
grdevices.dev_off() | |
from IPython.display import Image | |
Image("kNNdistplot.png") |
Author
thistleknot
commented
May 2, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment