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]:
In [2]:
ggplot(pigeons, aes(x='pos', y='speed')) + \
geom_point() + \
stat_smooth(se=True, color='coral')
Out[2]:
In [3]:
ggplot(pigeons, aes(x='pos', y='speed')) + \
geom_point() + \
stat_smooth(color='red')
Out[3]:
In [4]:
ggplot(mtcars, aes(x='mpg', y='cyl', color='steelblue')) + geom_point()
Out[4]:
In [5]:
ggplot(mtcars, aes(x='mpg', y='cyl')) + geom_point(color='green')
Out[5]:
In [6]:
ggplot(diamonds, aes(x='carat', y='price')) + geom_point() + facet_wrap('clarity', ncol=4)
Out[6]:
In [7]:
ggplot(diamonds, aes(x='carat', y='price')) + geom_point() + facet_wrap('clarity', nrow=5)
Out[7]:
In [8]:
ggplot(diamonds, aes(x='carat', y='price')) + geom_point() + facet_grid(x='clarity')
Out[8]:
In [9]:
ggplot(diamonds, aes(x='carat', y='price')) + geom_point() + facet_grid(y='clarity')
Out[9]:
In [10]:
ggplot(diamonds, aes(x='carat', y='price')) + geom_point() + facet_wrap(x='clarity', y='cut')
Out[10]:
In [11]:
ggplot(diamonds, aes(x='carat', y='price')) + geom_point() + facet_wrap(x='clarity')
Out[11]:
In [12]:
ggplot(diamonds, aes(x='carat', y='price')) + geom_point() + facet_wrap(y='clarity')
Out[12]:
In [13]:
ggplot(diamonds, aes(x='carat', y='price', size='clarity')) + geom_point()
Out[13]:
In [14]:
ggplot(diamonds, aes(x='carat', y='price', size='x')) + geom_point()
Out[14]:
In [15]:
ggplot(diamonds, aes(x='carat', y='price', alpha='x')) + geom_point()
Out[15]:
In [16]:
ggplot(diamonds, aes(x='carat', y='price', alpha='x')) + geom_point() + facet_grid(x='clarity')
Out[16]:
In [17]:
ggplot(diamonds, aes(x='carat', y='price', alpha='x')) + geom_point() + facet_grid(y='clarity')
Out[17]:
In [18]:
ggplot(diamonds, aes(x='carat', y='price', shape='clarity')) + geom_point()
Out[18]:
In [19]:
ggplot(diamonds, aes(x='carat', y='price', shape='cut', color='clarity')) + geom_point() + scale_color_brewer() + facet_grid(x='color')
Out[19]:
In [20]:
ggplot(diamonds, aes(x='carat', y='price')) + geom_point() + scale_color_brewer() + facet_grid(x='color', y='clarity')
Out[20]:
In [21]:
ggplot(diamonds, aes(x='carat', y='price', shape='cut', color='clarity')) + geom_point() + scale_color_brewer() + facet_grid(y='color')
Out[21]:
In [22]:
ggplot(diamonds, aes(x='carat', y='price', color='clarity')) + geom_point() + scale_color_brewer(type='div')
Out[22]:
In [23]:
ggplot(diamonds, aes(x='carat', y='price', color='x')) + geom_point()
Out[23]:
In [25]:
ggplot(diamonds, aes(x='carat', y='price', linetype='cut')) + geom_line()
Out[25]:
In [26]:
ggplot(diamonds, aes(x='carat')) + geom_histogram()
Out[26]:
In [27]:
ggplot(diamonds, aes(x='carat', y='price')) + geom_point()
Out[27]:
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]:
In [29]:
ggplot(diamonds, aes(x='carat')) + geom_density()
Out[29]:
In [30]:
ggplot(diamonds, aes(x='price')) + geom_hline(y=10)
Out[30]:
In [31]:
ggplot(diamonds, aes(x='price')) + geom_vline(x=10)
Out[31]:
In [32]:
ggplot(diamonds, aes(x='clarity')) + geom_bar()
Out[32]:
In [33]:
ggplot(diamonds, aes(x='clarity', weight='x')) + geom_bar()
Out[33]:
In [34]:
ggplot(diamonds, aes(x='carat', y='price')) + geom_point() + geom_abline(slope=5000, intercept=-500)
Out[34]:
In [35]:
ggplot(diamonds, aes(x='carat', y='price')) + geom_point() + geom_abline(slope=5000, intercept=-500) + facet_wrap(y='clarity')
Out[35]:
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]:
In [37]:
ggplot(diamonds, aes(x='carat', y='price')) + geom_point() + facet_wrap(x='clarity')
Out[37]:
In [38]:
p = ggplot(diamonds, aes(x='carat', y='price')) + geom_point() + facet_wrap(x='color', y='cut')
p
Out[38]:
In [39]:
ggplot(diamonds, aes(x='carat', y='price')) + geom_point() + facet_grid(x='color')
Out[39]:
In [40]:
ggplot(diamonds, aes(x='carat', y='price')) + geom_point() + facet_grid(y='color')
Out[40]:
In [41]:
ggplot(diamonds, aes(x='price')) + geom_histogram() + facet_grid(x='color', y='cut')
Out[41]:
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]:
In [43]:
ggplot(df, aes(x='x', y='y')) + geom_point() + coord_equal()
Out[43]:
In [44]:
ggplot(df, aes(x='x', y='y')) + geom_point() + coord_flip()
Out[44]:
In [45]:
ggplot(df, aes(x='x', y='y')) + geom_point() + coord_flip() + facet_grid(x='z')
Out[45]:
In [46]:
ggplot(pageviews, aes(x='date_hour', y='pageviews')) + geom_line() + scale_x_date(labels=date_format('%B %-d, %Y'))
Out[46]:
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]:
In [48]:
ggplot(pageviews, aes(x='date_hour', y='pageviews')) + geom_line()
Out[48]:
In [ ]: