GithubHelp home page GithubHelp logo

ctguxp / pyggplot Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tyberiusprime/pyggplot

0.0 2.0 0.0 3.23 MB

Pythonic wrapper for R's ggplot using rpy2 and pandas

License: BSD 3-Clause "New" or "Revised" License

Python 100.00%

pyggplot's Introduction

pyggplot

pyggplot is a Pythonic wrapper around the R ggplot2 library.

It is based on a a straightforward take Pandas data frames and shove them into R via rpy2 approach.

Examples

Please visit http://nbviewer.ipython.org/url/tyberiusprime.github.io/pyggplot/pyggplot%20samples.ipynb

Installation

The easiest installation is via PyPI.

$ pip install pyggplot

You may be required to update pandas, rpy2, so you may be required to run

$ pip install --upgrade pyggplot 

Usage

import pandas as pd
import numpy as np
import ggplot

df = pd.DataFrame({'x': np.random.rand(100),
                   'y': np.random.randn(100),
                   'group': ['A','B'] * 50})

p = pyggplot.Plot(df)
p.add_scatter('x','y', color='group')
p.render('output.png')
## or if you want to use it in IPython Notebook
# p.render_notebook()

Further usage

Takes a pandas.DataFrame object, then add layers with the various add_xyz functions (e.g. add_scatter).

Refer to the ggplot documentation about the layers (geoms), and simply replace geom_* with add_*. See: http://docs.ggplot2.org/0.9.3.1/index.html

You do not need to separate aesthetics from values - the wrapper will treat a parameter as value if and only if it is not a column name. (so y = 0 is a value, color = 'blue' is a value - except if you have a column 'blue', then it is a column!. And y = 'value' does not work, but that seems to be a ggplot issue).

When the DataFrame is passed to R:

  • row indices are turned into columns with 'reset_index',
  • multi level column indices are flattened by concatenating them with ' ', that is (X, 'mean') becomes 'x mean'.

Error messages are not great - most of them translate to 'one or more columns were not found', but they can appear as a lot of different actual messages such as

  • argument "env" is missing, with no default
  • object 'y' not found
  • object 'dat_0' not found
  • requires the following missing aesthetics: x
  • non numeric argument to binary operator

without actually quite pointing at what is strictly the offending value. Also, the error appears when rendering (or printing in the IPython Notebook), not when adding the layer.

Open questions

  • the stat support is not great - it doesn't easily map into pythonic objects. For now, do your stats in pandas - more powerful anyhow!
  • how could error messages be improved?

Other ggplots' for python

pyggplot's People

Contributors

tyberiusprime avatar ffinkernagel avatar stared avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.