In [1]:
from ggplot import *
import pandas as pd
import numpy as np
In [2]:
meat.tail()
Out[2]:
In [3]:
diamonds.head()
Out[3]:
In [4]:
pageviews.head()
Out[4]:
In [5]:
mtcars.head()
Out[5]:
In [6]:
aes(x='wt', y='mpg')
Out[6]:
In [7]:
ggplot(aes(x='wt', y='mpg'))
In [8]:
p = ggplot(mtcars, aes(x='wt', y='mpg'))
In [9]:
p = ggplot(aes(x='wt', y='mpg'), data=mtcars)
This is blank because we didn't pass the plot any "layers"
In [10]:
p
Out[10]:
Let's add some points...
In [11]:
p + geom_point()
Out[11]:
You can see all of them here.
In [12]:
p + geom_point()
Out[12]:
In [13]:
ggplot(aes(x='date', y='beef'), data=meat) + geom_line()
Out[13]:
In [14]:
df = pd.DataFrame({"x": range(100)})
df['y'] = np.random.choice([-1, 1], 100)
df.y = df.y.cumsum()
In [15]:
ggplot(aes(x='x', y='y'), data=df) + geom_step()
Out[15]:
In [16]:
ggplot(aes(x='carat'), data=diamonds) + geom_histogram()
Out[16]:
In [17]:
df = pd.DataFrame(dict(x=np.random.normal(0, 1, 10000)))
ggplot(df, aes(x='x')) + geom_density()
Out[17]:
In [18]:
ggplot(aes(x='date', y='beef'), data=meat) +\
geom_point(color='red', alpha=0.3) +\
geom_line()
Out[18]:
In [19]:
ggplot(aes(x='wt', y='mpg'), data=mtcars) +\
geom_point() +\
geom_abline(color='blue', slope=-5, intercept=40)
Out[19]:
In [20]:
ggplot(aes(x='wt', y='mpg'), data=mtcars) +\
geom_point(color="blue", size=200) +\
geom_point(color="white", size = 100) +\
geom_point(color="red", size = 25)
Out[20]:
In [21]:
ggplot(aes(x='wt', y='mpg'), data=mtcars) +\
geom_point(color="blue", size=200) +\
geom_point(color="white", size = 100) +\
geom_point(color="red", size = 25) +\
geom_vline(x=4.5)
Out[21]:
In [22]:
ggplot(aes(x='wt', y='mpg'), data=mtcars) +\
geom_point(color="blue", size=200) +\
geom_point(color="white", size = 100) +\
geom_point(color="red", size = 25) +\
geom_hline(y=12.5) +\
geom_vline(x=4.5)
Out[22]: