sirrice / pygg Goto Github PK
View Code? Open in Web Editor NEWggplot2 syntax in python. Actually wrapper around Wickham's ggplot2 in R
License: MIT License
ggplot2 syntax in python. Actually wrapper around Wickham's ggplot2 in R
License: MIT License
Maybe the R script can generate a standalone pygg_functions.py file that pygg.py can import *? That way don't need to copy and paste in the future
Current version of ggplot() takes a variable name as input, by default "data", and relies on ggsave()'s prefix argument to set the data object.
ggplot('data', aes(...)) + ggsave(..., prefix=data_py(dataobject))
Modify ggplot() call to accept a data object as input, and let it configure the prefix under the covers. ggsave's prefix argument option can still be used for full control
The current code uses a hardcoded tempfile /tmp/_pygg_data.csv, which may cause conflicts between multiple versions of ggpy running on the same machine as well as leaks data onto the filesystem that lives after the lifetime of a program using pygg. Replace with a true temporary file from tempfile.
Are there alternatives that do something similar for Networks? I can only find some for R.
In this R script, there are two data: mean_wt and mtcars. However, current pygg only resolve one data and can not resolve the mean_wt.
mean_wt <- data.frame(cyl = c(4, 6, 8), wt = c(2.28, 3.11, 4.00))
ggplot(mtcars, aes(mpg, wt, colour = wt)) +
geom_point() +
geom_hline(aes(yintercept = wt, colour = wt), mean_wt) +
facet_wrap(~ cyl)
Example source
facet_grid and facet_wrap have a special API right now to handle the formulas in R. Update the code so that the interface isn't specialized and you use the functions directly with escaped strings:
Today:
p = p + facet_grid('x', 'y')
Proposed API:
p = p + facet_grid(esc("x ~ y"))
Current unit tests for pygg are too limited in scope. Many individual functions (e.g., data_py, is_pandas_df, to_r) can be tested quite effectively.
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
Is there any progress on python 3 compatibility?
Right now to_r doesn't understand basic python types like lists and dictionaries and it would be more nature to use those data structures when invoking ggplot via pygg in some function calls. to_r should be generalized to recursively convert common python data structures to reasonable R equivalents.
For example, right you can you have to say:
p += pygg.scale_y_continuous(limits="c(0, 1)")
but it would be more natural to be able to say this as:
p += pygg.scale_y_continuous(limits=[0, 1])
I am not familiar with the Python-R bindings, but glancing over pygg
's codebase it seems fairly doable.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.