I am trying to run some R code from within a python script. To do this I am using rpy2 but having difficulty (could also just call an R script but I can't get that to work either). Below is the R script code that does what I want it to do:
library(ggplot2)
setwd("/dir/")
allelefreqshort <- read.table("allelefreqsshort.txt", header = TRUE)
hist(log10(allelefreqshort$AlleleFreq), xlim = c(-15,0), breaks=20)
This is my rpy2 code, and it plots the data but not as log10 and also the x axis is too small.
import rpy2.robjects as ro
from rpy2.robjects.packages import importr
r = ro.r
outputDir = '/dir'
r.setwd(outputDir)
f = r('read.table("allelefreqs.txt", header = FALSE)')
grdevices = importr('grDevices')
grdevices.png(file="alleleFreq.png", width=800, height=500)
r.hist(f[0], breaks=100, main = '5 Reads', xlab='Variant Freq', ylab='# Vars', log10='x')
grdevices.dev_off()