In [1]:
%matplotlib inline
from ggplot import *
import pandas as pd
import numpy as np

In [8]:
ggplot(diamonds, aes(x='price', color='clarity')) + \
    geom_density() + \
    scale_color_brewer(type='div', palette=7) + \
    facet_wrap('cut')


Out[8]:
<ggplot: (297867089)>

In [2]:
ggplot(pigeons, aes(x='pos', y='speed')) + \
    geom_point() + \
    stat_smooth(se=True, color='coral')


Out[2]:
<ggplot: (284780789)>

In [3]:
ggplot(pigeons, aes(x='pos', y='speed')) + \
    geom_point() + \
    stat_smooth(color='red')


Out[3]:
<ggplot: (285147001)>

In [4]:
ggplot(mtcars, aes(x='mpg', y='cyl', color='steelblue')) + geom_point()


Out[4]:
<ggplot: (286861869)>

In [5]:
ggplot(mtcars, aes(x='mpg', y='cyl')) + geom_point(color='green')


Out[5]:
<ggplot: (287076453)>

In [6]:
ggplot(diamonds, aes(x='carat', y='price')) + geom_point() + facet_wrap('clarity', ncol=4)


Out[6]:
<ggplot: (287138089)>

In [7]:
ggplot(diamonds, aes(x='carat', y='price')) + geom_point() + facet_wrap('clarity', nrow=5)


Out[7]:
<ggplot: (290664813)>

In [8]:
ggplot(diamonds, aes(x='carat', y='price')) + geom_point() + facet_grid(x='clarity')


Out[8]:
<ggplot: (291920649)>

In [9]:
ggplot(diamonds, aes(x='carat', y='price')) + geom_point() + facet_grid(y='clarity')


Out[9]:
<ggplot: (294555929)>

In [10]:
ggplot(diamonds, aes(x='carat', y='price')) + geom_point() + facet_wrap(x='clarity', y='cut')


Out[10]:
<ggplot: (296510101)>

In [11]:
ggplot(diamonds, aes(x='carat', y='price')) + geom_point() + facet_wrap(x='clarity')


Out[11]:
<ggplot: (301470333)>

In [12]:
ggplot(diamonds, aes(x='carat', y='price')) + geom_point() + facet_wrap(y='clarity')


Out[12]:
<ggplot: (303165473)>

In [13]:
ggplot(diamonds, aes(x='carat', y='price', size='clarity')) + geom_point()


Out[13]:
<ggplot: (304486325)>

In [14]:
ggplot(diamonds, aes(x='carat', y='price', size='x')) + geom_point()


Out[14]:
<ggplot: (301995149)>

In [15]:
ggplot(diamonds, aes(x='carat', y='price', alpha='x')) + geom_point()


Out[15]:
<ggplot: (304786009)>

In [16]:
ggplot(diamonds, aes(x='carat', y='price', alpha='x')) + geom_point() + facet_grid(x='clarity')


Out[16]:
<ggplot: (305096213)>

In [17]:
ggplot(diamonds, aes(x='carat', y='price', alpha='x')) + geom_point() + facet_grid(y='clarity')


Out[17]:
<ggplot: (310442441)>

In [18]:
ggplot(diamonds, aes(x='carat', y='price', shape='clarity')) + geom_point()


Out[18]:
<ggplot: (301470241)>

In [19]:
ggplot(diamonds, aes(x='carat', y='price', shape='cut', color='clarity')) + geom_point() + scale_color_brewer() + facet_grid(x='color')


Out[19]:
<ggplot: (324640385)>

In [20]:
ggplot(diamonds, aes(x='carat', y='price')) + geom_point() + scale_color_brewer() + facet_grid(x='color', y='clarity')


Out[20]:
<ggplot: (326754717)>

In [21]:
ggplot(diamonds, aes(x='carat', y='price', shape='cut', color='clarity')) + geom_point() + scale_color_brewer() + facet_grid(y='color')


Out[21]:
<ggplot: (333752553)>

In [22]:
ggplot(diamonds, aes(x='carat', y='price', color='clarity')) + geom_point() + scale_color_brewer(type='div')


Out[22]:
<ggplot: (333649525)>

In [23]:
ggplot(diamonds, aes(x='carat', y='price', color='x')) + geom_point()


Out[23]:
<ggplot: (316606333)>

In [25]:
ggplot(diamonds, aes(x='carat', y='price', linetype='cut')) + geom_line()


Out[25]:
<ggplot: (333754201)>

In [26]:
ggplot(diamonds, aes(x='carat')) + geom_histogram()


Out[26]:
<ggplot: (338392809)>

In [27]:
ggplot(diamonds, aes(x='carat', y='price')) + geom_point()


Out[27]:
<ggplot: (338639581)>

In [28]:
ggplot(diamonds, aes(x='carat', y='price', color='clarity')) + geom_point() + xlab("THIS IS AN X LABEL") + ylab("THIS IS A Y LABEL") + ggtitle("THIS IS A TITLE")


Out[28]:
<ggplot: (338644045)>

In [29]:
ggplot(diamonds, aes(x='carat')) + geom_density()


Out[29]:
<ggplot: (338935237)>

In [30]:
ggplot(diamonds, aes(x='price')) + geom_hline(y=10)


Out[30]:
<ggplot: (340655637)>

In [31]:
ggplot(diamonds, aes(x='price')) + geom_vline(x=10)


Out[31]:
<ggplot: (340815569)>

In [32]:
ggplot(diamonds, aes(x='clarity')) + geom_bar()


Out[32]:
<ggplot: (341295301)>

In [33]:
ggplot(diamonds, aes(x='clarity', weight='x')) + geom_bar()


Out[33]:
<ggplot: (342622533)>

In [34]:
ggplot(diamonds, aes(x='carat', y='price')) + geom_point() + geom_abline(slope=5000, intercept=-500)


Out[34]:
<ggplot: (343277437)>

In [35]:
ggplot(diamonds, aes(x='carat', y='price')) + geom_point() + geom_abline(slope=5000, intercept=-500) + facet_wrap(y='clarity')


Out[35]:
<ggplot: (343812453)>

In [36]:
df = pd.DataFrame({"x": np.arange(1000)})
df['y_low'] = df.x * 0.9
df['y_high'] = df.x * 1.1
df['thing'] = ['a' if i%2==0 else 'b' for i in df.x]
# p = ggplot(df, aes(x='x', ymin='y_low', ymax='y_high')) + geom_area()
# print """p = ggplot(df, aes(x='x', ymin='y_low', ymax='y_high')) + geom_area()""",  p
# area w/ facet
p = ggplot(df, aes(x='x', ymin='y_low', ymax='y_high')) + geom_area() + facet_wrap(x='thing')
p


Out[36]:
<ggplot: (345716529)>

In [37]:
ggplot(diamonds, aes(x='carat', y='price')) + geom_point() + facet_wrap(x='clarity')


Out[37]:
<ggplot: (345683649)>

In [38]:
p = ggplot(diamonds, aes(x='carat', y='price')) + geom_point() + facet_wrap(x='color', y='cut')
p


Out[38]:
<ggplot: (327576221)>

In [39]:
ggplot(diamonds, aes(x='carat', y='price')) + geom_point() + facet_grid(x='color')


Out[39]:
<ggplot: (332696229)>

In [40]:
ggplot(diamonds, aes(x='carat', y='price')) + geom_point() + facet_grid(y='color')


Out[40]:
<ggplot: (351225925)>

In [41]:
ggplot(diamonds, aes(x='price')) + geom_histogram() + facet_grid(x='color', y='cut')


Out[41]:
<ggplot: (353552601)>

In [42]:
df = pd.DataFrame({"x": np.arange(100)})
df['y'] = df.x * 10
df['z'] = ["a" if x%2==0 else "b" for x in df.x]

# polar coords
p = ggplot(df, aes(x='x', y='y')) + geom_point() + coord_polar()
p


Out[42]:
<ggplot: (350769977)>

In [43]:
ggplot(df, aes(x='x', y='y')) + geom_point() + coord_equal()


Out[43]:
<ggplot: (357809697)>

In [44]:
ggplot(df, aes(x='x', y='y')) + geom_point() + coord_flip()


Out[44]:
<ggplot: (356803533)>

In [45]:
ggplot(df, aes(x='x', y='y')) + geom_point() + coord_flip() + facet_grid(x='z')


Out[45]:
<ggplot: (359645433)>

In [46]:
ggplot(pageviews, aes(x='date_hour', y='pageviews')) + geom_line() + scale_x_date(labels=date_format('%B %-d, %Y'))


Out[46]:
<ggplot: (360496341)>

In [47]:
pageviews['z'] = ["a" if i%2==0 else "b" for i in range(len(pageviews))]
p = ggplot(pageviews, aes(x='date_hour', y='pageviews')) + geom_line() + scale_x_date(labels=date_format('%B %-d, %Y')) + facet_grid(y='z')
p


Out[47]:
<ggplot: (360511901)>

In [48]:
ggplot(pageviews, aes(x='date_hour', y='pageviews')) + geom_line()


Out[48]:
<ggplot: (360519433)>

In [ ]: