In [1]:
%matplotlib inline
from ggplot import *
In [2]:
ggplot(mtcars, aes(x='mpg')) + geom_histogram() + xlab("This is my X Label")
Out[2]:
In [3]:
ggplot(mtcars, aes(x='mpg')) + geom_histogram() + xlab("This is my X\nIs on Multiple Lines")
Out[3]:
In [4]:
ggplot(mtcars, aes(x='mpg')) + geom_histogram() + xlab("Miles per Gallon") + ylab("# of Cars")
Out[4]:
In [5]:
ggplot(mtcars, aes(x='mpg')) + geom_histogram() + ggtitle("This is my Title")
Out[5]:
In [6]:
ggplot(mtcars, aes(x='mpg')) + geom_histogram() + ggtitle("This is my Title\nOn Two Lines")
Out[6]:
In [7]:
ggplot(diamonds, aes(x='carat', y='price')) + geom_point() + xlim(0, 4)
Out[7]:
In [8]:
ggplot(diamonds, aes(x='carat', y='price')) + geom_point() + xlim(0, 4) + ylim(0, 20000)
Out[8]:
In [9]:
ggplot(diamonds, aes(x='carat', y='price')) + \
geom_point() + \
xlim(0, 4) + \
ylim(0, 20000) + \
scale_x_continuous("Carat", breaks=[0, 2, 4])
Out[9]:
In [10]:
ggplot(diamonds, aes(x='carat', y='price')) + \
geom_point() + \
xlim(0, 4) + \
ylim(0, 20000) + \
scale_x_continuous("Carat", breaks=[0, 2, 4], labels=["Small", "Medium", "Large"])
Out[10]:
In [11]:
ggplot(diamonds, aes(x='carat', y='price')) + \
geom_point() + \
xlim(0, 4) + \
ylim(0, 20000) + \
scale_x_continuous("Carat (200mg)", breaks=[0, 2, 4], labels=["Small", "Medium", "Large"]) + \
scale_y_continuous("Price ($)", breaks=[0, 10000, 20000], labels=["\$", "\$$", "\$\$$"])
Out[11]:
In [12]:
ggplot(diamonds, aes(x='carat', y='price')) + \
geom_point() + \
geom_hline(y=2500, color='red') + \
xlim(0, 4) + \
ylim(0, 20000) + \
scale_x_continuous("Carat (200mg)", breaks=[0, 2, 4], labels=["Small", "Medium", "Large"]) + \
scale_y_continuous("Price", breaks=[0, 2500, 10000, 20000], labels=["", "You better be above here", "\$$", "\$\$$"])
Out[12]:
In [13]:
ggplot(diamonds, aes(x='cut')) + \
geom_bar()
Out[13]:
In [14]:
ggplot(diamonds, aes(x='cut')) + \
geom_bar() + \
scale_x_discrete("Diamond Cut")
Out[14]:
In [15]:
ggplot(diamonds, aes(x='cut')) + \
geom_bar() + \
scale_x_discrete("Diamond Cut", labels=["i", "p", "vg", "g", "f"])
Out[15]:
In [16]:
ggplot(diamonds, aes(x='cut')) + \
geom_bar() + \
scale_x_discrete("Diamond Cut", labels=["*", "**", "***", "****", "*****"])
Out[16]:
In [ ]: