sirrice / pygg

ggplot2 syntax in python. Actually wrapper around Wickham's ggplot2 in R
MIT License
73 stars 9 forks source link

Error with stat='identity' in geom_bar #18

Closed elvis-sik closed 7 years ago

elvis-sik commented 7 years ago

A minimal example is

import pygg
import pandas as pd

data = pd.DataFrame({'x': range(10), 'y': range(10, 20)})
p = pygg.ggplot(data, pygg.aes(x='x', y='y'))
g = pygg.geom_bar(stat='identity')
pygg.ggsave('file.png', p + g, data=None)

The traceback says

ValueError: ggplot2 bridge failed for program: library(ggplot2)

data = read.csv("/tmp/tmpICcyg2",sep=",")

p = ggplot(data,aes(x=x,y=y)) + geom_bar(stat=identity)
ggsave("file.png",p,height=8,scale=1,width=10). Check for an error
sirrice commented 7 years ago

due to how strings are translated into R the following python statement:

pygg.geom_bar(stat='identity')

is translated into the following incorrect R script

geom_bar(stat=identity)

The way to get around this is to wrap the python script with pygg's esc():

pygg.geom_bar(stat=esc('identity'))

or to do it manually:

pygg.geom_bar(stat="'identity'")

elvis-sik commented 7 years ago

Thanks for your patience, now I see it has been documented since long before I opened this issue.