Gadfly

Carlos Lizama

Outline:

  1. Introduction
  2. The grammar of graphics
  3. Plotting arrays and functions.
  4. Plotting DataFrames
  5. Pros and Cons.

Introduction

  1. Leland Wilkinson (2005) created the Grammar of Graphics to describe deep features that underlie all statistical graphics.

The grammar tells us that a statistical graphic is a mapping from data to aesthetic attributes (color, shape, size) of geometric objects (points, lines, bars). The plot may also contain statistical transformation of the data and is drawn on a specific coordinate system. Faceting can be used to generate that same plot for different subsets of dataset. It is the combination of these independent components that make up a graphic.

  1. Hadley Wickham (2009) builds on Wilkinson's grammar and adapts it within R. He develops the ggplot2 package.
  2. Gadfly is a package that implements the Grammar of Graphics in Julia, based mainly on ggplot2.

The grammar of graphics

The main components of the grammar:

  1. The Data that we want to visualize and a set of asthetic mappings describing how variables in the data are mapped to aethetic attributes which define how the data should be perceived.
  2. Geometric object, geoms for short, represent what we actually see on the plot: points, lines, polygons, etc.
  3. Statistical transformation, stats for shor, summarize data in many useful ways. For instance, the binning to create histograms. Stats are optional, but very useful.
  4. The scales map values in the data space to values in an aesthetic space, whether it be color, size or shape. Scales also draw legend or axes.
  5. A coordinate system, coor for short, describes how data coordinates are mapped to the plane of the graphic. It also provides axes and gridlines to make it possible to read the graph. Examples of coordinate system are the Cartesian cordinate system and the polar coordinate system.
  6. A faceting specification describes how to break up the data into subsets and how to display those subsets as small multiples.

The Grammar of Graphics in Julia

In Julia, we can speficy:

  1. aethetics, scales, coordinates, guides, geometries, stats.

Data

  • The Data is supplied in form of DataFrame.
  • Although the DataFrame is optional.

Statistics

  • Statistics are functions taking as input one or more aesthetics, operating on those values, then output to one or more aesthetics. For example, drawing of boxplots typically uses the boxplot statistic (Stat.boxplot) that takes as input the x and y aesthetic, and outputs the middle, and upper and lower hinge, and upper and lower fence aesthetics.

Scales

  • Scales, similarly to statistics, apply a transformation to the original data, typically mapping one aesthetic to the same aesthetic, while retaining the original value, e.g. Scale.x_log

Geometries

  • Geometries are responsible for actually doing the drawing. A geometry takes as input one or more aesthetics, and used data bound to these aesthetics to draw things.

Guides

  • Very similar to geometries are guides, which draw graphics supporting the actual visualization, such as axis ticks and labels and color keys. The major distinction is that geometries always draw within the rectangular plot frame, while guides have some special layout considerations.

In [1]:
using Gadfly

Examples Gadfly

Plotting arrays and anonymous functions


In [2]:
# plot arrays

x = collect(linspace(-5,5,8))
y = 5*cos(x)+x
plot(x=x, y=y)


Out[2]:
x -20 -15 -10 -5 0 5 10 15 20 -15.0 -14.5 -14.0 -13.5 -13.0 -12.5 -12.0 -11.5 -11.0 -10.5 -10.0 -9.5 -9.0 -8.5 -8.0 -7.5 -7.0 -6.5 -6.0 -5.5 -5.0 -4.5 -4.0 -3.5 -3.0 -2.5 -2.0 -1.5 -1.0 -0.5 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0 10.5 11.0 11.5 12.0 12.5 13.0 13.5 14.0 14.5 15.0 -20 -10 0 10 20 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 -35 -30 -25 -20 -15 -10 -5 0 5 10 15 20 25 30 35 -30 -29 -28 -27 -26 -25 -24 -23 -22 -21 -20 -19 -18 -17 -16 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 -40 -20 0 20 40 -30 -28 -26 -24 -22 -20 -18 -16 -14 -12 -10 -8 -6 -4 -2 0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 y

In [3]:
# line options: point, line, smooth. Use Geom.
x = collect(linspace(-5,5,8))
y = 5*cos(x)+x
plot(x=x, y=y, Geom.step())  # optional arguments: direction :vh :hv


Out[3]:
x -20 -15 -10 -5 0 5 10 15 20 -15.0 -14.5 -14.0 -13.5 -13.0 -12.5 -12.0 -11.5 -11.0 -10.5 -10.0 -9.5 -9.0 -8.5 -8.0 -7.5 -7.0 -6.5 -6.0 -5.5 -5.0 -4.5 -4.0 -3.5 -3.0 -2.5 -2.0 -1.5 -1.0 -0.5 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0 10.5 11.0 11.5 12.0 12.5 13.0 13.5 14.0 14.5 15.0 -20 -10 0 10 20 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 -35 -30 -25 -20 -15 -10 -5 0 5 10 15 20 25 30 35 -30 -29 -28 -27 -26 -25 -24 -23 -22 -21 -20 -19 -18 -17 -16 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 -40 -20 0 20 40 -30 -28 -26 -24 -22 -20 -18 -16 -14 -12 -10 -8 -6 -4 -2 0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 y

In [4]:
# plot anonymous fuctions
plot([sin, cos], -5, 5)


Out[4]:
x -20 -15 -10 -5 0 5 10 15 20 -15.0 -14.5 -14.0 -13.5 -13.0 -12.5 -12.0 -11.5 -11.0 -10.5 -10.0 -9.5 -9.0 -8.5 -8.0 -7.5 -7.0 -6.5 -6.0 -5.5 -5.0 -4.5 -4.0 -3.5 -3.0 -2.5 -2.0 -1.5 -1.0 -0.5 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0 10.5 11.0 11.5 12.0 12.5 13.0 13.5 14.0 14.5 15.0 -20 -10 0 10 20 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 f1 f2 Color -3.5 -3.0 -2.5 -2.0 -1.5 -1.0 -0.5 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 -3.0 -2.9 -2.8 -2.7 -2.6 -2.5 -2.4 -2.3 -2.2 -2.1 -2.0 -1.9 -1.8 -1.7 -1.6 -1.5 -1.4 -1.3 -1.2 -1.1 -1.0 -0.9 -0.8 -0.7 -0.6 -0.5 -0.4 -0.3 -0.2 -0.1 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 -4 -2 0 2 4 -3.0 -2.8 -2.6 -2.4 -2.2 -2.0 -1.8 -1.6 -1.4 -1.2 -1.0 -0.8 -0.6 -0.4 -0.2 0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0 2.2 2.4 2.6 2.8 3.0 f(x)

In [5]:
plot([x->5*cos(x) + x, x->5*sin(x) + x], -5, 5)


Out[5]:
x -20 -15 -10 -5 0 5 10 15 20 -15.0 -14.5 -14.0 -13.5 -13.0 -12.5 -12.0 -11.5 -11.0 -10.5 -10.0 -9.5 -9.0 -8.5 -8.0 -7.5 -7.0 -6.5 -6.0 -5.5 -5.0 -4.5 -4.0 -3.5 -3.0 -2.5 -2.0 -1.5 -1.0 -0.5 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0 10.5 11.0 11.5 12.0 12.5 13.0 13.5 14.0 14.5 15.0 -20 -10 0 10 20 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 f1 f2 Color -35 -30 -25 -20 -15 -10 -5 0 5 10 15 20 25 30 35 -30 -29 -28 -27 -26 -25 -24 -23 -22 -21 -20 -19 -18 -17 -16 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 -40 -20 0 20 40 -30 -28 -26 -24 -22 -20 -18 -16 -14 -12 -10 -8 -6 -4 -2 0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 f(x)

In [6]:
f(x) = 5*cos(x) + x


Out[6]:
f (generic function with 1 method)

In [7]:
# customize plots: title, axis, labels, ...
plot(f, -4, 4, Guide.xlabel("variable x"), Guide.ylabel("variable y=f(x)"), Guide.title("This is the title"))


Out[7]:
variable x -14 -12 -10 -8 -6 -4 -2 0 2 4 6 8 10 12 14 -12.0 -11.5 -11.0 -10.5 -10.0 -9.5 -9.0 -8.5 -8.0 -7.5 -7.0 -6.5 -6.0 -5.5 -5.0 -4.5 -4.0 -3.5 -3.0 -2.5 -2.0 -1.5 -1.0 -0.5 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0 10.5 11.0 11.5 12.0 -20 -10 0 10 20 -12.0 -11.5 -11.0 -10.5 -10.0 -9.5 -9.0 -8.5 -8.0 -7.5 -7.0 -6.5 -6.0 -5.5 -5.0 -4.5 -4.0 -3.5 -3.0 -2.5 -2.0 -1.5 -1.0 -0.5 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0 10.5 11.0 11.5 12.0 -35 -30 -25 -20 -15 -10 -5 0 5 10 15 20 25 30 35 -30 -29 -28 -27 -26 -25 -24 -23 -22 -21 -20 -19 -18 -17 -16 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 -40 -20 0 20 40 -30 -28 -26 -24 -22 -20 -18 -16 -14 -12 -10 -8 -6 -4 -2 0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 variable y=f(x) This is the title

In [8]:
# more on Guide, xrug, yrug. 
plot(x=x, y=y, Guide.xrug, Guide.yrug)


Out[8]:
x -20 -15 -10 -5 0 5 10 15 20 -15.0 -14.5 -14.0 -13.5 -13.0 -12.5 -12.0 -11.5 -11.0 -10.5 -10.0 -9.5 -9.0 -8.5 -8.0 -7.5 -7.0 -6.5 -6.0 -5.5 -5.0 -4.5 -4.0 -3.5 -3.0 -2.5 -2.0 -1.5 -1.0 -0.5 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0 10.5 11.0 11.5 12.0 12.5 13.0 13.5 14.0 14.5 15.0 -20 -10 0 10 20 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 -35 -30 -25 -20 -15 -10 -5 0 5 10 15 20 25 30 35 -30 -29 -28 -27 -26 -25 -24 -23 -22 -21 -20 -19 -18 -17 -16 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 -40 -20 0 20 40 -30 -28 -26 -24 -22 -20 -18 -16 -14 -12 -10 -8 -6 -4 -2 0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 y

In [9]:
# more on guide: ticks
xt = [-3, -2, 3, 4]
yt = [-1, 0, 2]
plot(x=x, y=y, Geom.line, Guide.xticks(ticks=xt, orientation=:vertical), Guide.yticks(ticks=yt))
# optional: label: true or false.


Out[9]:
x -3 -2 3 4 -1 0 2 y

In [10]:
# more than one plot at the same time: layers
y1 = y+1
plot(layer(x=x, y=y, Geom.line), layer(x=x, y=y1, Geom.smooth, Theme(default_color=colorant"red")))


Out[10]:
x -20 -15 -10 -5 0 5 10 15 20 -15.0 -14.5 -14.0 -13.5 -13.0 -12.5 -12.0 -11.5 -11.0 -10.5 -10.0 -9.5 -9.0 -8.5 -8.0 -7.5 -7.0 -6.5 -6.0 -5.5 -5.0 -4.5 -4.0 -3.5 -3.0 -2.5 -2.0 -1.5 -1.0 -0.5 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0 10.5 11.0 11.5 12.0 12.5 13.0 13.5 14.0 14.5 15.0 -20 -10 0 10 20 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 -35 -30 -25 -20 -15 -10 -5 0 5 10 15 20 25 30 35 -30 -29 -28 -27 -26 -25 -24 -23 -22 -21 -20 -19 -18 -17 -16 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 -40 -20 0 20 40 -30 -28 -26 -24 -22 -20 -18 -16 -14 -12 -10 -8 -6 -4 -2 0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 y

In [11]:
# others: Geom: vline, hline.
plot(x=x, y=y, xintercept=[4], yintercept=[-2], Geom.line, Geom.hline(), Geom.vline(color=colorant"orange", size=1mm))


Out[11]:
x -20 -15 -10 -5 0 5 10 15 20 -15.0 -14.5 -14.0 -13.5 -13.0 -12.5 -12.0 -11.5 -11.0 -10.5 -10.0 -9.5 -9.0 -8.5 -8.0 -7.5 -7.0 -6.5 -6.0 -5.5 -5.0 -4.5 -4.0 -3.5 -3.0 -2.5 -2.0 -1.5 -1.0 -0.5 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0 10.5 11.0 11.5 12.0 12.5 13.0 13.5 14.0 14.5 15.0 -20 -10 0 10 20 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 -35 -30 -25 -20 -15 -10 -5 0 5 10 15 20 25 30 35 -30 -29 -28 -27 -26 -25 -24 -23 -22 -21 -20 -19 -18 -17 -16 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 -40 -20 0 20 40 -30 -28 -26 -24 -22 -20 -18 -16 -14 -12 -10 -8 -6 -4 -2 0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 y

In [12]:
# histograms
x0 = randn(10000)
plot(x=x0, Geom.histogram)


Out[12]:
x -14 -12 -10 -8 -6 -4 -2 0 2 4 6 8 10 12 14 -12.0 -11.5 -11.0 -10.5 -10.0 -9.5 -9.0 -8.5 -8.0 -7.5 -7.0 -6.5 -6.0 -5.5 -5.0 -4.5 -4.0 -3.5 -3.0 -2.5 -2.0 -1.5 -1.0 -0.5 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0 10.5 11.0 11.5 12.0 -20 -10 0 10 20 -12.0 -11.5 -11.0 -10.5 -10.0 -9.5 -9.0 -8.5 -8.0 -7.5 -7.0 -6.5 -6.0 -5.5 -5.0 -4.5 -4.0 -3.5 -3.0 -2.5 -2.0 -1.5 -1.0 -0.5 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0 10.5 11.0 11.5 12.0 -300 -250 -200 -150 -100 -50 0 50 100 150 200 250 300 350 400 450 500 550 -250 -240 -230 -220 -210 -200 -190 -180 -170 -160 -150 -140 -130 -120 -110 -100 -90 -80 -70 -60 -50 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200 210 220 230 240 250 260 270 280 290 300 310 320 330 340 350 360 370 380 390 400 410 420 430 440 450 460 470 480 490 500 -250 0 250 500 -260 -240 -220 -200 -180 -160 -140 -120 -100 -80 -60 -40 -20 0 20 40 60 80 100 120 140 160 180 200 220 240 260 280 300 320 340 360 380 400 420 440 460 480 500

In [13]:
# Scale. x_continuous, y_continuous, x_log, x_log10, etc. Same for y.
plot(x=x, y=y, Scale.x_continuous(format=:scientific), Geom.line)


Out[13]:
x -2.0×10¹ -1.5×10¹ -1.0×10¹ -5.0×10⁰ 0 5.0×10⁰ 1.0×10¹ 1.5×10¹ 2.0×10¹ -1.50×10¹ -1.45×10¹ -1.40×10¹ -1.35×10¹ -1.30×10¹ -1.25×10¹ -1.20×10¹ -1.15×10¹ -1.10×10¹ -1.05×10¹ -1.00×10¹ -9.50×10⁰ -9.00×10⁰ -8.50×10⁰ -8.00×10⁰ -7.50×10⁰ -7.00×10⁰ -6.50×10⁰ -6.00×10⁰ -5.50×10⁰ -5.00×10⁰ -4.50×10⁰ -4.00×10⁰ -3.50×10⁰ -3.00×10⁰ -2.50×10⁰ -2.00×10⁰ -1.50×10⁰ -1.00×10⁰ -5.00×10⁻¹ 0 5.00×10⁻¹ 1.00×10⁰ 1.50×10⁰ 2.00×10⁰ 2.50×10⁰ 3.00×10⁰ 3.50×10⁰ 4.00×10⁰ 4.50×10⁰ 5.00×10⁰ 5.50×10⁰ 6.00×10⁰ 6.50×10⁰ 7.00×10⁰ 7.50×10⁰ 8.00×10⁰ 8.50×10⁰ 9.00×10⁰ 9.50×10⁰ 1.00×10¹ 1.05×10¹ 1.10×10¹ 1.15×10¹ 1.20×10¹ 1.25×10¹ 1.30×10¹ 1.35×10¹ 1.40×10¹ 1.45×10¹ 1.50×10¹ -2×10¹ -1×10¹ 0 1×10¹ 2×10¹ -1.5×10¹ -1.4×10¹ -1.3×10¹ -1.2×10¹ -1.1×10¹ -1.0×10¹ -9.0×10⁰ -8.0×10⁰ -7.0×10⁰ -6.0×10⁰ -5.0×10⁰ -4.0×10⁰ -3.0×10⁰ -2.0×10⁰ -1.0×10⁰ 0 1.0×10⁰ 2.0×10⁰ 3.0×10⁰ 4.0×10⁰ 5.0×10⁰ 6.0×10⁰ 7.0×10⁰ 8.0×10⁰ 9.0×10⁰ 1.0×10¹ 1.1×10¹ 1.2×10¹ 1.3×10¹ 1.4×10¹ 1.5×10¹ -35 -30 -25 -20 -15 -10 -5 0 5 10 15 20 25 30 35 -30 -29 -28 -27 -26 -25 -24 -23 -22 -21 -20 -19 -18 -17 -16 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 -40 -20 0 20 40 -30 -28 -26 -24 -22 -20 -18 -16 -14 -12 -10 -8 -6 -4 -2 0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 y

In [14]:
# Coord.cartesian xmin, xmax
plot(x=x, y=y, Coord.cartesian(xmin=-2,xmax=4))


Out[14]:
x -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 -8.0 -7.8 -7.6 -7.4 -7.2 -7.0 -6.8 -6.6 -6.4 -6.2 -6.0 -5.8 -5.6 -5.4 -5.2 -5.0 -4.8 -4.6 -4.4 -4.2 -4.0 -3.8 -3.6 -3.4 -3.2 -3.0 -2.8 -2.6 -2.4 -2.2 -2.0 -1.8 -1.6 -1.4 -1.2 -1.0 -0.8 -0.6 -0.4 -0.2 0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0 2.2 2.4 2.6 2.8 3.0 3.2 3.4 3.6 3.8 4.0 4.2 4.4 4.6 4.8 5.0 5.2 5.4 5.6 5.8 6.0 6.2 6.4 6.6 6.8 7.0 7.2 7.4 7.6 7.8 8.0 8.2 8.4 8.6 8.8 9.0 9.2 9.4 9.6 9.8 10.0 -10 -5 0 5 10 -8.0 -7.5 -7.0 -6.5 -6.0 -5.5 -5.0 -4.5 -4.0 -3.5 -3.0 -2.5 -2.0 -1.5 -1.0 -0.5 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0 -35 -30 -25 -20 -15 -10 -5 0 5 10 15 20 25 30 35 -30 -29 -28 -27 -26 -25 -24 -23 -22 -21 -20 -19 -18 -17 -16 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 -40 -20 0 20 40 -30 -28 -26 -24 -22 -20 -18 -16 -14 -12 -10 -8 -6 -4 -2 0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 y

In [15]:
# Scale. x_continuous, y_continuous, x_log, x_log10, etc. Same for y.
x1 = collect(linspace(0,1,10))
y1 = exp(x1)
plot(x=x1, y=y1, Scale.y_log())


Out[15]:
x -1.5 -1.0 -0.5 0.0 0.5 1.0 1.5 2.0 2.5 -1.00 -0.95 -0.90 -0.85 -0.80 -0.75 -0.70 -0.65 -0.60 -0.55 -0.50 -0.45 -0.40 -0.35 -0.30 -0.25 -0.20 -0.15 -0.10 -0.05 0.00 0.05 0.10 0.15 0.20 0.25 0.30 0.35 0.40 0.45 0.50 0.55 0.60 0.65 0.70 0.75 0.80 0.85 0.90 0.95 1.00 1.05 1.10 1.15 1.20 1.25 1.30 1.35 1.40 1.45 1.50 1.55 1.60 1.65 1.70 1.75 1.80 1.85 1.90 1.95 2.00 -1 0 1 2 -1.0 -0.9 -0.8 -0.7 -0.6 -0.5 -0.4 -0.3 -0.2 -0.1 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 e-1.5 e-1.0 e-0.5 e0.0 e0.5 e1.0 e1.5 e2.0 e2.5 e-1.00 e-0.95 e-0.90 e-0.85 e-0.80 e-0.75 e-0.70 e-0.65 e-0.60 e-0.55 e-0.50 e-0.45 e-0.40 e-0.35 e-0.30 e-0.25 e-0.20 e-0.15 e-0.10 e-0.05 e0.00 e0.05 e0.10 e0.15 e0.20 e0.25 e0.30 e0.35 e0.40 e0.45 e0.50 e0.55 e0.60 e0.65 e0.70 e0.75 e0.80 e0.85 e0.90 e0.95 e1.00 e1.05 e1.10 e1.15 e1.20 e1.25 e1.30 e1.35 e1.40 e1.45 e1.50 e1.55 e1.60 e1.65 e1.70 e1.75 e1.80 e1.85 e1.90 e1.95 e2.00 e-1 e0 e1 e2 e-1.0 e-0.9 e-0.8 e-0.7 e-0.6 e-0.5 e-0.4 e-0.3 e-0.2 e-0.1 e0.0 e0.1 e0.2 e0.3 e0.4 e0.5 e0.6 e0.7 e0.8 e0.9 e1.0 e1.1 e1.2 e1.3 e1.4 e1.5 e1.6 e1.7 e1.8 e1.9 e2.0 y

In [16]:
# Other features: Geom.path
n = 10
xjumps = randn(n)
yjumps = randn(n)
plot(x=cumsum(xjumps),y=cumsum(yjumps),Geom.path())


Out[16]:
x -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 -6.0 -5.8 -5.6 -5.4 -5.2 -5.0 -4.8 -4.6 -4.4 -4.2 -4.0 -3.8 -3.6 -3.4 -3.2 -3.0 -2.8 -2.6 -2.4 -2.2 -2.0 -1.8 -1.6 -1.4 -1.2 -1.0 -0.8 -0.6 -0.4 -0.2 0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0 2.2 2.4 2.6 2.8 3.0 3.2 3.4 3.6 3.8 4.0 4.2 4.4 4.6 4.8 5.0 5.2 5.4 5.6 5.8 6.0 -6 -3 0 3 6 -6.0 -5.5 -5.0 -4.5 -4.0 -3.5 -3.0 -2.5 -2.0 -1.5 -1.0 -0.5 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 -6.0 -5.8 -5.6 -5.4 -5.2 -5.0 -4.8 -4.6 -4.4 -4.2 -4.0 -3.8 -3.6 -3.4 -3.2 -3.0 -2.8 -2.6 -2.4 -2.2 -2.0 -1.8 -1.6 -1.4 -1.2 -1.0 -0.8 -0.6 -0.4 -0.2 0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0 2.2 2.4 2.6 2.8 3.0 3.2 3.4 3.6 3.8 4.0 4.2 4.4 4.6 4.8 5.0 5.2 5.4 5.6 5.8 6.0 6.2 6.4 6.6 6.8 7.0 7.2 7.4 7.6 7.8 8.0 8.2 8.4 8.6 8.8 9.0 9.2 9.4 9.6 9.8 10.0 10.2 10.4 10.6 10.8 11.0 11.2 11.4 11.6 11.8 12.0 -10 0 10 20 -6.0 -5.5 -5.0 -4.5 -4.0 -3.5 -3.0 -2.5 -2.0 -1.5 -1.0 -0.5 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0 10.5 11.0 11.5 12.0 y

In [17]:
# Other features: Geom.ribbon
ymin = y - 1
ymax = y + 1
plot(x=x, y=y, ymax=ymax, ymin=ymin, Geom.line, Geom.ribbon)


Out[17]:
x -20 -15 -10 -5 0 5 10 15 20 -15.0 -14.5 -14.0 -13.5 -13.0 -12.5 -12.0 -11.5 -11.0 -10.5 -10.0 -9.5 -9.0 -8.5 -8.0 -7.5 -7.0 -6.5 -6.0 -5.5 -5.0 -4.5 -4.0 -3.5 -3.0 -2.5 -2.0 -1.5 -1.0 -0.5 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0 10.5 11.0 11.5 12.0 12.5 13.0 13.5 14.0 14.5 15.0 -20 -10 0 10 20 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 -35 -30 -25 -20 -15 -10 -5 0 5 10 15 20 25 30 35 -30 -29 -28 -27 -26 -25 -24 -23 -22 -21 -20 -19 -18 -17 -16 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 -40 -20 0 20 40 -30 -28 -26 -24 -22 -20 -18 -16 -14 -12 -10 -8 -6 -4 -2 0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 y

Plotting Datasets


In [18]:
using RDatasets
using DataFrames

In [19]:
Data1 = dataset("car","Salaries")
# The 2008-09 nine-month academic salary for Assistant Professors, Associate Professors and 
# Professors in a college in the U.S.


Out[19]:
RankDisciplineYrsSincePhDYrsServiceSexSalary
1ProfB1918Male139750
2ProfB2016Male173200
3AsstProfB43Male79750
4ProfB4539Male115000
5ProfB4041Male141500
6AssocProfB66Male97000
7ProfB3023Male175000
8ProfB4545Male147765
9ProfB2120Male119250
10ProfB1818Female129000
11AssocProfB128Male119800
12AsstProfB72Male79800
13AsstProfB11Male77700
14AsstProfB20Male78000
15ProfB2018Male104800
16ProfB123Male117150
17ProfB1920Male101000
18ProfA3834Male103450
19ProfA3723Male124750
20ProfA3936Female137000
21ProfA3126Male89565
22ProfA3631Male102580
23ProfA3430Male93904
24ProfA2419Male113068
25AssocProfA138Female74830
26ProfA218Male106294
27ProfA3523Male134885
28AsstProfB53Male82379
29AsstProfB110Male77000
30ProfB128Male118223
&vellip&vellip&vellip&vellip&vellip&vellip&vellip

In [20]:
# density
plot(Data1, x="Salary", Geom.density)   # Geom.density = Geom.line, Stat.density


Out[20]:
Salary -4×10⁵ -3×10⁵ -2×10⁵ -1×10⁵ 0 1×10⁵ 2×10⁵ 3×10⁵ 4×10⁵ 5×10⁵ 6×10⁵ 7×10⁵ -3.0×10⁵ -2.9×10⁵ -2.8×10⁵ -2.7×10⁵ -2.6×10⁵ -2.5×10⁵ -2.4×10⁵ -2.3×10⁵ -2.2×10⁵ -2.1×10⁵ -2.0×10⁵ -1.9×10⁵ -1.8×10⁵ -1.7×10⁵ -1.6×10⁵ -1.5×10⁵ -1.4×10⁵ -1.3×10⁵ -1.2×10⁵ -1.1×10⁵ -1.0×10⁵ -9.0×10⁴ -8.0×10⁴ -7.0×10⁴ -6.0×10⁴ -5.0×10⁴ -4.0×10⁴ -3.0×10⁴ -2.0×10⁴ -1.0×10⁴ 0 1.0×10⁴ 2.0×10⁴ 3.0×10⁴ 4.0×10⁴ 5.0×10⁴ 6.0×10⁴ 7.0×10⁴ 8.0×10⁴ 9.0×10⁴ 1.0×10⁵ 1.1×10⁵ 1.2×10⁵ 1.3×10⁵ 1.4×10⁵ 1.5×10⁵ 1.6×10⁵ 1.7×10⁵ 1.8×10⁵ 1.9×10⁵ 2.0×10⁵ 2.1×10⁵ 2.2×10⁵ 2.3×10⁵ 2.4×10⁵ 2.5×10⁵ 2.6×10⁵ 2.7×10⁵ 2.8×10⁵ 2.9×10⁵ 3.0×10⁵ 3.1×10⁵ 3.2×10⁵ 3.3×10⁵ 3.4×10⁵ 3.5×10⁵ 3.6×10⁵ 3.7×10⁵ 3.8×10⁵ 3.9×10⁵ 4.0×10⁵ 4.1×10⁵ 4.2×10⁵ 4.3×10⁵ 4.4×10⁵ 4.5×10⁵ 4.6×10⁵ 4.7×10⁵ 4.8×10⁵ 4.9×10⁵ 5.0×10⁵ 5.1×10⁵ 5.2×10⁵ 5.3×10⁵ 5.4×10⁵ 5.5×10⁵ 5.6×10⁵ 5.7×10⁵ 5.8×10⁵ 5.9×10⁵ 6.0×10⁵ -3×10⁵ 0 3×10⁵ 6×10⁵ -3.0×10⁵ -2.8×10⁵ -2.6×10⁵ -2.4×10⁵ -2.2×10⁵ -2.0×10⁵ -1.8×10⁵ -1.6×10⁵ -1.4×10⁵ -1.2×10⁵ -1.0×10⁵ -8.0×10⁴ -6.0×10⁴ -4.0×10⁴ -2.0×10⁴ 0 2.0×10⁴ 4.0×10⁴ 6.0×10⁴ 8.0×10⁴ 1.0×10⁵ 1.2×10⁵ 1.4×10⁵ 1.6×10⁵ 1.8×10⁵ 2.0×10⁵ 2.2×10⁵ 2.4×10⁵ 2.6×10⁵ 2.8×10⁵ 3.0×10⁵ 3.2×10⁵ 3.4×10⁵ 3.6×10⁵ 3.8×10⁵ 4.0×10⁵ 4.2×10⁵ 4.4×10⁵ 4.6×10⁵ 4.8×10⁵ 5.0×10⁵ 5.2×10⁵ 5.4×10⁵ 5.6×10⁵ 5.8×10⁵ 6.0×10⁵ -2.0×10⁻⁵ -1.5×10⁻⁵ -1.0×10⁻⁵ -5.0×10⁻⁶ 0 5.0×10⁻⁶ 1.0×10⁻⁵ 1.5×10⁻⁵ 2.0×10⁻⁵ 2.5×10⁻⁵ 3.0×10⁻⁵ 3.5×10⁻⁵ -1.50×10⁻⁵ -1.45×10⁻⁵ -1.40×10⁻⁵ -1.35×10⁻⁵ -1.30×10⁻⁵ -1.25×10⁻⁵ -1.20×10⁻⁵ -1.15×10⁻⁵ -1.10×10⁻⁵ -1.05×10⁻⁵ -1.00×10⁻⁵ -9.50×10⁻⁶ -9.00×10⁻⁶ -8.50×10⁻⁶ -8.00×10⁻⁶ -7.50×10⁻⁶ -7.00×10⁻⁶ -6.50×10⁻⁶ -6.00×10⁻⁶ -5.50×10⁻⁶ -5.00×10⁻⁶ -4.50×10⁻⁶ -4.00×10⁻⁶ -3.50×10⁻⁶ -3.00×10⁻⁶ -2.50×10⁻⁶ -2.00×10⁻⁶ -1.50×10⁻⁶ -1.00×10⁻⁶ -5.00×10⁻⁷ 0 5.00×10⁻⁷ 1.00×10⁻⁶ 1.50×10⁻⁶ 2.00×10⁻⁶ 2.50×10⁻⁶ 3.00×10⁻⁶ 3.50×10⁻⁶ 4.00×10⁻⁶ 4.50×10⁻⁶ 5.00×10⁻⁶ 5.50×10⁻⁶ 6.00×10⁻⁶ 6.50×10⁻⁶ 7.00×10⁻⁶ 7.50×10⁻⁶ 8.00×10⁻⁶ 8.50×10⁻⁶ 9.00×10⁻⁶ 9.50×10⁻⁶ 1.00×10⁻⁵ 1.05×10⁻⁵ 1.10×10⁻⁵ 1.15×10⁻⁵ 1.20×10⁻⁵ 1.25×10⁻⁵ 1.30×10⁻⁵ 1.35×10⁻⁵ 1.40×10⁻⁵ 1.45×10⁻⁵ 1.50×10⁻⁵ 1.55×10⁻⁵ 1.60×10⁻⁵ 1.65×10⁻⁵ 1.70×10⁻⁵ 1.75×10⁻⁵ 1.80×10⁻⁵ 1.85×10⁻⁵ 1.90×10⁻⁵ 1.95×10⁻⁵ 2.00×10⁻⁵ 2.05×10⁻⁵ 2.10×10⁻⁵ 2.15×10⁻⁵ 2.20×10⁻⁵ 2.25×10⁻⁵ 2.30×10⁻⁵ 2.35×10⁻⁵ 2.40×10⁻⁵ 2.45×10⁻⁵ 2.50×10⁻⁵ 2.55×10⁻⁵ 2.60×10⁻⁵ 2.65×10⁻⁵ 2.70×10⁻⁵ 2.75×10⁻⁵ 2.80×10⁻⁵ 2.85×10⁻⁵ 2.90×10⁻⁵ 2.95×10⁻⁵ 3.00×10⁻⁵ -2×10⁻⁵ 0 2×10⁻⁵ 4×10⁻⁵ -1.5×10⁻⁵ -1.4×10⁻⁵ -1.3×10⁻⁵ -1.2×10⁻⁵ -1.1×10⁻⁵ -1.0×10⁻⁵ -9.0×10⁻⁶ -8.0×10⁻⁶ -7.0×10⁻⁶ -6.0×10⁻⁶ -5.0×10⁻⁶ -4.0×10⁻⁶ -3.0×10⁻⁶ -2.0×10⁻⁶ -1.0×10⁻⁶ 0 1.0×10⁻⁶ 2.0×10⁻⁶ 3.0×10⁻⁶ 4.0×10⁻⁶ 5.0×10⁻⁶ 6.0×10⁻⁶ 7.0×10⁻⁶ 8.0×10⁻⁶ 9.0×10⁻⁶ 1.0×10⁻⁵ 1.1×10⁻⁵ 1.2×10⁻⁵ 1.3×10⁻⁵ 1.4×10⁻⁵ 1.5×10⁻⁵ 1.6×10⁻⁵ 1.7×10⁻⁵ 1.8×10⁻⁵ 1.9×10⁻⁵ 2.0×10⁻⁵ 2.1×10⁻⁵ 2.2×10⁻⁵ 2.3×10⁻⁵ 2.4×10⁻⁵ 2.5×10⁻⁵ 2.6×10⁻⁵ 2.7×10⁻⁵ 2.8×10⁻⁵ 2.9×10⁻⁵ 3.0×10⁻⁵

In [21]:
# histogram
plot(Data1, x="Salary", Geom.histogram, color="Discipline") # Geom.histogram = Geom.bar, Stat.histogram


Out[21]:
Salary -3.0×10⁵ -2.5×10⁵ -2.0×10⁵ -1.5×10⁵ -1.0×10⁵ -5.0×10⁴ 0 5.0×10⁴ 1.0×10⁵ 1.5×10⁵ 2.0×10⁵ 2.5×10⁵ 3.0×10⁵ 3.5×10⁵ 4.0×10⁵ 4.5×10⁵ 5.0×10⁵ 5.5×10⁵ -2.5×10⁵ -2.4×10⁵ -2.3×10⁵ -2.2×10⁵ -2.1×10⁵ -2.0×10⁵ -1.9×10⁵ -1.8×10⁵ -1.7×10⁵ -1.6×10⁵ -1.5×10⁵ -1.4×10⁵ -1.3×10⁵ -1.2×10⁵ -1.1×10⁵ -1.0×10⁵ -9.0×10⁴ -8.0×10⁴ -7.0×10⁴ -6.0×10⁴ -5.0×10⁴ -4.0×10⁴ -3.0×10⁴ -2.0×10⁴ -1.0×10⁴ 0 1.0×10⁴ 2.0×10⁴ 3.0×10⁴ 4.0×10⁴ 5.0×10⁴ 6.0×10⁴ 7.0×10⁴ 8.0×10⁴ 9.0×10⁴ 1.0×10⁵ 1.1×10⁵ 1.2×10⁵ 1.3×10⁵ 1.4×10⁵ 1.5×10⁵ 1.6×10⁵ 1.7×10⁵ 1.8×10⁵ 1.9×10⁵ 2.0×10⁵ 2.1×10⁵ 2.2×10⁵ 2.3×10⁵ 2.4×10⁵ 2.5×10⁵ 2.6×10⁵ 2.7×10⁵ 2.8×10⁵ 2.9×10⁵ 3.0×10⁵ 3.1×10⁵ 3.2×10⁵ 3.3×10⁵ 3.4×10⁵ 3.5×10⁵ 3.6×10⁵ 3.7×10⁵ 3.8×10⁵ 3.9×10⁵ 4.0×10⁵ 4.1×10⁵ 4.2×10⁵ 4.3×10⁵ 4.4×10⁵ 4.5×10⁵ 4.6×10⁵ 4.7×10⁵ 4.8×10⁵ 4.9×10⁵ 5.0×10⁵ -2.5×10⁵ 0 2.5×10⁵ 5.0×10⁵ -2.6×10⁵ -2.4×10⁵ -2.2×10⁵ -2.0×10⁵ -1.8×10⁵ -1.6×10⁵ -1.4×10⁵ -1.2×10⁵ -1.0×10⁵ -8.0×10⁴ -6.0×10⁴ -4.0×10⁴ -2.0×10⁴ 0 2.0×10⁴ 4.0×10⁴ 6.0×10⁴ 8.0×10⁴ 1.0×10⁵ 1.2×10⁵ 1.4×10⁵ 1.6×10⁵ 1.8×10⁵ 2.0×10⁵ 2.2×10⁵ 2.4×10⁵ 2.6×10⁵ 2.8×10⁵ 3.0×10⁵ 3.2×10⁵ 3.4×10⁵ 3.6×10⁵ 3.8×10⁵ 4.0×10⁵ 4.2×10⁵ 4.4×10⁵ 4.6×10⁵ 4.8×10⁵ 5.0×10⁵ B A Discipline -20 -15 -10 -5 0 5 10 15 20 25 30 35 -15.0 -14.5 -14.0 -13.5 -13.0 -12.5 -12.0 -11.5 -11.0 -10.5 -10.0 -9.5 -9.0 -8.5 -8.0 -7.5 -7.0 -6.5 -6.0 -5.5 -5.0 -4.5 -4.0 -3.5 -3.0 -2.5 -2.0 -1.5 -1.0 -0.5 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0 10.5 11.0 11.5 12.0 12.5 13.0 13.5 14.0 14.5 15.0 15.5 16.0 16.5 17.0 17.5 18.0 18.5 19.0 19.5 20.0 20.5 21.0 21.5 22.0 22.5 23.0 23.5 24.0 24.5 25.0 25.5 26.0 26.5 27.0 27.5 28.0 28.5 29.0 29.5 30.0 -20 0 20 40 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

In [22]:
# 2D histogram
plot(Data1, x="Salary", y="YrsService", Geom.histogram2d(xbincount=40, ybincount=40))


Out[22]:
Salary -3.0×10⁵ -2.5×10⁵ -2.0×10⁵ -1.5×10⁵ -1.0×10⁵ -5.0×10⁴ 0 5.0×10⁴ 1.0×10⁵ 1.5×10⁵ 2.0×10⁵ 2.5×10⁵ 3.0×10⁵ 3.5×10⁵ 4.0×10⁵ 4.5×10⁵ 5.0×10⁵ 5.5×10⁵ -2.5×10⁵ -2.4×10⁵ -2.3×10⁵ -2.2×10⁵ -2.1×10⁵ -2.0×10⁵ -1.9×10⁵ -1.8×10⁵ -1.7×10⁵ -1.6×10⁵ -1.5×10⁵ -1.4×10⁵ -1.3×10⁵ -1.2×10⁵ -1.1×10⁵ -1.0×10⁵ -9.0×10⁴ -8.0×10⁴ -7.0×10⁴ -6.0×10⁴ -5.0×10⁴ -4.0×10⁴ -3.0×10⁴ -2.0×10⁴ -1.0×10⁴ 0 1.0×10⁴ 2.0×10⁴ 3.0×10⁴ 4.0×10⁴ 5.0×10⁴ 6.0×10⁴ 7.0×10⁴ 8.0×10⁴ 9.0×10⁴ 1.0×10⁵ 1.1×10⁵ 1.2×10⁵ 1.3×10⁵ 1.4×10⁵ 1.5×10⁵ 1.6×10⁵ 1.7×10⁵ 1.8×10⁵ 1.9×10⁵ 2.0×10⁵ 2.1×10⁵ 2.2×10⁵ 2.3×10⁵ 2.4×10⁵ 2.5×10⁵ 2.6×10⁵ 2.7×10⁵ 2.8×10⁵ 2.9×10⁵ 3.0×10⁵ 3.1×10⁵ 3.2×10⁵ 3.3×10⁵ 3.4×10⁵ 3.5×10⁵ 3.6×10⁵ 3.7×10⁵ 3.8×10⁵ 3.9×10⁵ 4.0×10⁵ 4.1×10⁵ 4.2×10⁵ 4.3×10⁵ 4.4×10⁵ 4.5×10⁵ 4.6×10⁵ 4.7×10⁵ 4.8×10⁵ 4.9×10⁵ 5.0×10⁵ -2.5×10⁵ 0 2.5×10⁵ 5.0×10⁵ -2.6×10⁵ -2.4×10⁵ -2.2×10⁵ -2.0×10⁵ -1.8×10⁵ -1.6×10⁵ -1.4×10⁵ -1.2×10⁵ -1.0×10⁵ -8.0×10⁴ -6.0×10⁴ -4.0×10⁴ -2.0×10⁴ 0 2.0×10⁴ 4.0×10⁴ 6.0×10⁴ 8.0×10⁴ 1.0×10⁵ 1.2×10⁵ 1.4×10⁵ 1.6×10⁵ 1.8×10⁵ 2.0×10⁵ 2.2×10⁵ 2.4×10⁵ 2.6×10⁵ 2.8×10⁵ 3.0×10⁵ 3.2×10⁵ 3.4×10⁵ 3.6×10⁵ 3.8×10⁵ 4.0×10⁵ 4.2×10⁵ 4.4×10⁵ 4.6×10⁵ 4.8×10⁵ 5.0×10⁵ 1 4 2 6 8 Count -70 -60 -50 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 100 110 120 130 -60 -58 -56 -54 -52 -50 -48 -46 -44 -42 -40 -38 -36 -34 -32 -30 -28 -26 -24 -22 -20 -18 -16 -14 -12 -10 -8 -6 -4 -2 0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 -100 0 100 200 -60 -55 -50 -45 -40 -35 -30 -25 -20 -15 -10 -5 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 YrsService

In [23]:
# error bars
using Distributions

sds = [1, 1/2, 1/4, 1/8, 1/16, 1/32]
n = 10
ys = [mean(rand(Normal(0, sd), n)) for sd in sds]
ymins = ys .- (1.96 * sds / sqrt(n))
ymaxs = ys .+ (1.96 * sds / sqrt(n))

plot(x=1:length(sds), y=ys, ymin=ymins, ymax=ymaxs, Geom.point, Geom.errorbar)


Out[23]:
x -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 -6.0 -5.8 -5.6 -5.4 -5.2 -5.0 -4.8 -4.6 -4.4 -4.2 -4.0 -3.8 -3.6 -3.4 -3.2 -3.0 -2.8 -2.6 -2.4 -2.2 -2.0 -1.8 -1.6 -1.4 -1.2 -1.0 -0.8 -0.6 -0.4 -0.2 0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0 2.2 2.4 2.6 2.8 3.0 3.2 3.4 3.6 3.8 4.0 4.2 4.4 4.6 4.8 5.0 5.2 5.4 5.6 5.8 6.0 6.2 6.4 6.6 6.8 7.0 7.2 7.4 7.6 7.8 8.0 8.2 8.4 8.6 8.8 9.0 9.2 9.4 9.6 9.8 10.0 10.2 10.4 10.6 10.8 11.0 11.2 11.4 11.6 11.8 12.0 -10 0 10 20 -6.0 -5.5 -5.0 -4.5 -4.0 -3.5 -3.0 -2.5 -2.0 -1.5 -1.0 -0.5 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0 10.5 11.0 11.5 12.0 -3.0 -2.5 -2.0 -1.5 -1.0 -0.5 0.0 0.5 1.0 1.5 2.0 2.5 -2.50 -2.45 -2.40 -2.35 -2.30 -2.25 -2.20 -2.15 -2.10 -2.05 -2.00 -1.95 -1.90 -1.85 -1.80 -1.75 -1.70 -1.65 -1.60 -1.55 -1.50 -1.45 -1.40 -1.35 -1.30 -1.25 -1.20 -1.15 -1.10 -1.05 -1.00 -0.95 -0.90 -0.85 -0.80 -0.75 -0.70 -0.65 -0.60 -0.55 -0.50 -0.45 -0.40 -0.35 -0.30 -0.25 -0.20 -0.15 -0.10 -0.05 0.00 0.05 0.10 0.15 0.20 0.25 0.30 0.35 0.40 0.45 0.50 0.55 0.60 0.65 0.70 0.75 0.80 0.85 0.90 0.95 1.00 1.05 1.10 1.15 1.20 1.25 1.30 1.35 1.40 1.45 1.50 1.55 1.60 1.65 1.70 1.75 1.80 1.85 1.90 1.95 2.00 -4 -2 0 2 -2.5 -2.4 -2.3 -2.2 -2.1 -2.0 -1.9 -1.8 -1.7 -1.6 -1.5 -1.4 -1.3 -1.2 -1.1 -1.0 -0.9 -0.8 -0.7 -0.6 -0.5 -0.4 -0.3 -0.2 -0.1 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 y

In [24]:
Data2 = dataset("datasets","USArrests")
# This data set contains statistics, in arrests per 100,000 residents for assault, murder, and rape in 
# each of the 50 US states in 1973. Also given is the percent of the population living in urban areas.


Out[24]:
StateMurderAssaultUrbanPopRape
1Alabama13.22365821.2
2Alaska10.02634844.5
3Arizona8.12948031.0
4Arkansas8.81905019.5
5California9.02769140.6
6Colorado7.92047838.7
7Connecticut3.31107711.1
8Delaware5.92387215.8
9Florida15.43358031.9
10Georgia17.42116025.8
11Hawaii5.3468320.2
12Idaho2.61205414.2
13Illinois10.42498324.0
14Indiana7.21136521.0
15Iowa2.2565711.3
16Kansas6.01156618.0
17Kentucky9.71095216.3
18Louisiana15.42496622.2
19Maine2.183517.8
20Maryland11.33006727.8
21Massachusetts4.41498516.3
22Michigan12.12557435.1
23Minnesota2.7726614.9
24Mississippi16.12594417.1
25Missouri9.01787028.2
26Montana6.01095316.4
27Nebraska4.31026216.5
28Nevada12.22528146.0
29New Hampshire2.157569.5
30New Jersey7.41598918.8
&vellip&vellip&vellip&vellip&vellip&vellip

In [25]:
# labels
plot(Data2, x="UrbanPop", y="Murder", label="State" , Geom.label, Geom.point)


Out[25]:
UrbanPop -125 -100 -75 -50 -25 0 25 50 75 100 125 150 175 200 225 -100 -95 -90 -85 -80 -75 -70 -65 -60 -55 -50 -45 -40 -35 -30 -25 -20 -15 -10 -5 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125 130 135 140 145 150 155 160 165 170 175 180 185 190 195 200 -100 0 100 200 -100 -90 -80 -70 -60 -50 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200 Alabama Alaska Arizona Arkansas California Colorado Connecticut Delaware Florida Georgia Hawaii Idaho Illinois Indiana Iowa Kansas Kentucky Louisiana Maine Maryland Massachusetts Michigan Minnesota Mississippi Missouri Montana Nebraska Nevada New Hampshire New Jersey New Mexico New York North Carolina North Dakota Ohio Oklahoma Oregon Pennsylvania Rhode Island South Carolina South Dakota Tennessee Texas Utah Vermont Virginia Washington West Virginia Wisconsin Wyoming -25 -20 -15 -10 -5 0 5 10 15 20 25 30 35 40 45 -20 -19 -18 -17 -16 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 -20 0 20 40 -20 -18 -16 -14 -12 -10 -8 -6 -4 -2 0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 Murder

In [26]:
Data3 = dataset("datasets","chickwts")
# An experiment was conducted to measure and compare the effectiveness of various feed supplements 
# on the growth rate of chickens.


Out[26]:
WeightFeed
1179horsebean
2160horsebean
3136horsebean
4227horsebean
5217horsebean
6168horsebean
7108horsebean
8124horsebean
9143horsebean
10140horsebean
11309linseed
12229linseed
13181linseed
14141linseed
15260linseed
16203linseed
17148linseed
18169linseed
19213linseed
20257linseed
21244linseed
22271linseed
23243soybean
24230soybean
25248soybean
26327soybean
27329soybean
28250soybean
29193soybean
30271soybean
&vellip&vellip&vellip

In [27]:
# boxplot
plot(Data3, x="Feed", y="Weight", Geom.boxplot)


Out[27]:
Feed horsebean linseed soybean sunflower meatmeal casein -600 -500 -400 -300 -200 -100 0 100 200 300 400 500 600 700 800 900 1000 1100 -500 -480 -460 -440 -420 -400 -380 -360 -340 -320 -300 -280 -260 -240 -220 -200 -180 -160 -140 -120 -100 -80 -60 -40 -20 0 20 40 60 80 100 120 140 160 180 200 220 240 260 280 300 320 340 360 380 400 420 440 460 480 500 520 540 560 580 600 620 640 660 680 700 720 740 760 780 800 820 840 860 880 900 920 940 960 980 1000 -500 0 500 1000 -500 -450 -400 -350 -300 -250 -200 -150 -100 -50 0 50 100 150 200 250 300 350 400 450 500 550 600 650 700 750 800 850 900 950 1000 Weight

In [28]:
# Data by categories.
Data4 = dataset("Ecdat","Wages1")
# a panel of 595 observations from 1976 to 1982


Out[28]:
ExperSexSchoolWage
19female136.3152956461
212female125.4797699786
311female113.6421699174
49female144.5933365997
58female142.4181574607
69female142.0940581101
78female125.5120039196
810female123.5484271597
912female105.8182263596
107female123.8277804998
1110female146.7368936796
1210female1312.861342479
1310female137.6555609995
149female102.4497795198
1510female136.1056621468
163female158.2680058795
179female141.8624054829
1813female113.9808917197
1910female124.7634601775
2011female126.3805955861
218female145.6311238472
227female112.4880573248
237female141.2237382772
245female121.3456535391
255female140.7511116452
2610female1411.330230279
2711female123.8947576562
286female132.9985152513
2911female123.2678961879
309female121.3551971812
&vellip&vellip&vellip&vellip&vellip

In [29]:
plot(Data4, x="Exper", y="Wage", color="Sex")


Out[29]:
Exper -25 -20 -15 -10 -5 0 5 10 15 20 25 30 35 40 45 -20 -19 -18 -17 -16 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 -20 0 20 40 -20 -18 -16 -14 -12 -10 -8 -6 -4 -2 0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 female male Sex -50 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 -40 -38 -36 -34 -32 -30 -28 -26 -24 -22 -20 -18 -16 -14 -12 -10 -8 -6 -4 -2 0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 -50 0 50 100 -40 -35 -30 -25 -20 -15 -10 -5 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 Wage

In [30]:
Data5 = dataset("Zelig", "approval")
# The (approximately) quarterly approval rating for the President of the United States from the first month of 2001
# to the last month of 2005.


Out[30]:
MonthYearApproveDisapproveUnsureSeptOct2001IraqWarAvgPrice
12200158.6723.6717.6700144.975
23200158.026.6715.3300140.925
34200160.529.510.000155.16
45200155.033.3311.6700170.175
56200154.034.012.000161.625
67200156.534.09.500142.06
78200156.035.09.000142.075
89200175.6718.336.010152.15
910200188.09.03.010131.54
1011200187.08.674.3300117.05
1112200186.010.53.500108.6
121200283.6712.673.6700110.725
132200282.014.04.000111.375
143200279.2515.755.000124.925
154200276.2519.04.7500139.7
165200276.3317.676.000139.175
176200273.420.26.400138.225
187200270.523.56.000139.7
198200266.527.06.500139.575
209200267.228.24.600139.96
2110200264.7529.06.2500144.525
2211200266.3327.06.6700141.9
2312200262.7531.55.7500138.58
241200360.1735.04.8300145.75
252200358.7535.755.500161.3
263200365.230.64.201169.3
274200370.025.754.2501158.9
285200366.3330.03.6701149.725
296200362.034.333.6700149.28
307200359.6736.673.6700151.25
&vellip&vellip&vellip&vellip&vellip&vellip&vellip&vellip&vellip

In [31]:
plot(Data5, x="Month",  y="Approve", color="Year", Geom.line)


Out[31]:
Month -20 -15 -10 -5 0 5 10 15 20 25 30 35 -15.0 -14.5 -14.0 -13.5 -13.0 -12.5 -12.0 -11.5 -11.0 -10.5 -10.0 -9.5 -9.0 -8.5 -8.0 -7.5 -7.0 -6.5 -6.0 -5.5 -5.0 -4.5 -4.0 -3.5 -3.0 -2.5 -2.0 -1.5 -1.0 -0.5 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0 10.5 11.0 11.5 12.0 12.5 13.0 13.5 14.0 14.5 15.0 15.5 16.0 16.5 17.0 17.5 18.0 18.5 19.0 19.5 20.0 20.5 21.0 21.5 22.0 22.5 23.0 23.5 24.0 24.5 25.0 25.5 26.0 26.5 27.0 27.5 28.0 28.5 29.0 29.5 30.0 -20 0 20 40 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 2002 2001 2003 2005 2004 2006 Year -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 -30 -28 -26 -24 -22 -20 -18 -16 -14 -12 -10 -8 -6 -4 -2 0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 -50 0 50 100 150 -30 -25 -20 -15 -10 -5 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125 130 135 140 145 150 Approve

In [32]:
Data6 = dataset("Zelig","macro")
# Selected macroeconomic indicators for many countries.


Out[32]:
CountryYearGDPUnemCapMobTrade
1United States19665.11114073.809.622906
2United States19672.27728293.809.983546
3United States19684.73.6010.08912
4United States19692.83.5010.43593
5United States1970-0.24.9010.49535
6United States19713.15.9011.27827
7United States19725.45.6011.21771
8United States19735.74.9011.76705
9United States1974-0.95.6013.77255
10United States1975-0.88.5017.42326
11United States19764.77.7016.52211
12United States19775.57.1017.23492
13United States19784.76.1017.54099
14United States19792.65.8018.17591
15United States1980-0.47.1019.73285
16United States19813.47.5021.51057
17United States1982-3.09.5020.53895
18United States19832.99.5018.56972
19United States19847.27.5017.81588
20United States19853.87.1018.02899
21United States19862.87.0017.20371
22United States19873.76.2017.23095
23United States19884.65.5018.29418
24United States19892.85.2700837019.413526
25United States19900.95.4145596020.638364
26Canada19666.80216763.6038.45467
27Canada19672.92364584.1040.16167
28Canada19685.64.8041.06574
29Canada19695.24.7042.76849
30Canada19702.65.9044.16533
&vellip&vellip&vellip&vellip&vellip&vellip&vellip

In [33]:
plot(Data6, x = "Year", y="GDP", color="Country", Geom.line)


Out[33]:
Year 1935 1940 1945 1950 1955 1960 1965 1970 1975 1980 1985 1990 1995 2000 2005 2010 2015 2020 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 1940 1960 1980 2000 2020 1940 1942 1944 1946 1948 1950 1952 1954 1956 1958 1960 1962 1964 1966 1968 1970 1972 1974 1976 1978 1980 1982 1984 1986 1988 1990 1992 1994 1996 1998 2000 2002 2004 2006 2008 2010 2012 2014 2016 United States Canada United Kingdom Netherlands Belgium France West Germany Austria Italy Finland Sweden Norway Denmark Japan Country -30 -25 -20 -15 -10 -5 0 5 10 15 20 25 30 35 40 -25 -24 -23 -22 -21 -20 -19 -18 -17 -16 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 -40 -20 0 20 40 -25 -20 -15 -10 -5 0 5 10 15 20 25 30 35 GDP

In [34]:
Data7 = dataset("vcd","Suicide")
# Data from Heuer (1979) on suicide rates in West Germany classified by age, sex, and method of suicide.


Out[34]:
FreqSexMethodAgeAgeGroupMethod2
14malepoison1010-20poison
20malecookgas1010-20gas
30maletoxicgas1010-20gas
4247malehang1010-20hang
51maledrown1010-20drown
617malegun1010-20gun
71maleknife1010-20knife
86malejump1010-20jump
90maleother1010-20other
10348malepoison1510-20poison
117malecookgas1510-20gas
1267maletoxicgas1510-20gas
13578malehang1510-20hang
1422maledrown1510-20drown
15179malegun1510-20gun
1611maleknife1510-20knife
1774malejump1510-20jump
18175maleother1510-20other
19808malepoison2010-20poison
2032malecookgas2010-20gas
21229maletoxicgas2010-20gas
22699malehang2010-20hang
2344maledrown2010-20drown
24316malegun2010-20gun
2535maleknife2010-20knife
26109malejump2010-20jump
27289maleother2010-20other
28789malepoison2525-35poison
2926malecookgas2525-35gas
30243maletoxicgas2525-35gas
&vellip&vellip&vellip&vellip&vellip&vellip&vellip

In [35]:
# grouped data.
p = plot(Data7, xgroup="Sex", ygroup="Method", x="Age", y="Freq", Geom.subplot_grid(Geom.bar))


Out[35]:
Age by Sex female male -150 -100 -50 0 50 100 150 200 250 -100 -95 -90 -85 -80 -75 -70 -65 -60 -55 -50 -45 -40 -35 -30 -25 -20 -15 -10 -5 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125 130 135 140 145 150 155 160 165 170 175 180 185 190 195 200 -100 0 100 200 -100 -90 -80 -70 -60 -50 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200 -150 -100 -50 0 50 100 150 200 250 -100 -95 -90 -85 -80 -75 -70 -65 -60 -55 -50 -45 -40 -35 -30 -25 -20 -15 -10 -5 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125 130 135 140 145 150 155 160 165 170 175 180 185 190 195 200 -100 0 100 200 -100 -90 -80 -70 -60 -50 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200 -2000 -1500 -1000 -500 0 500 1000 1500 2000 2500 3000 3500 -1500 -1450 -1400 -1350 -1300 -1250 -1200 -1150 -1100 -1050 -1000 -950 -900 -850 -800 -750 -700 -650 -600 -550 -500 -450 -400 -350 -300 -250 -200 -150 -100 -50 0 50 100 150 200 250 300 350 400 450 500 550 600 650 700 750 800 850 900 950 1000 1050 1100 1150 1200 1250 1300 1350 1400 1450 1500 1550 1600 1650 1700 1750 1800 1850 1900 1950 2000 2050 2100 2150 2200 2250 2300 2350 2400 2450 2500 2550 2600 2650 2700 2750 2800 2850 2900 2950 3000 -2000 0 2000 4000 -1500 -1400 -1300 -1200 -1100 -1000 -900 -800 -700 -600 -500 -400 -300 -200 -100 0 100 200 300 400 500 600 700 800 900 1000 1100 1200 1300 1400 1500 1600 1700 1800 1900 2000 2100 2200 2300 2400 2500 2600 2700 2800 2900 3000 other -2000 -1500 -1000 -500 0 500 1000 1500 2000 2500 3000 3500 -1500 -1450 -1400 -1350 -1300 -1250 -1200 -1150 -1100 -1050 -1000 -950 -900 -850 -800 -750 -700 -650 -600 -550 -500 -450 -400 -350 -300 -250 -200 -150 -100 -50 0 50 100 150 200 250 300 350 400 450 500 550 600 650 700 750 800 850 900 950 1000 1050 1100 1150 1200 1250 1300 1350 1400 1450 1500 1550 1600 1650 1700 1750 1800 1850 1900 1950 2000 2050 2100 2150 2200 2250 2300 2350 2400 2450 2500 2550 2600 2650 2700 2750 2800 2850 2900 2950 3000 -2000 0 2000 4000 -1500 -1400 -1300 -1200 -1100 -1000 -900 -800 -700 -600 -500 -400 -300 -200 -100 0 100 200 300 400 500 600 700 800 900 1000 1100 1200 1300 1400 1500 1600 1700 1800 1900 2000 2100 2200 2300 2400 2500 2600 2700 2800 2900 3000 jump -2000 -1500 -1000 -500 0 500 1000 1500 2000 2500 3000 3500 -1500 -1450 -1400 -1350 -1300 -1250 -1200 -1150 -1100 -1050 -1000 -950 -900 -850 -800 -750 -700 -650 -600 -550 -500 -450 -400 -350 -300 -250 -200 -150 -100 -50 0 50 100 150 200 250 300 350 400 450 500 550 600 650 700 750 800 850 900 950 1000 1050 1100 1150 1200 1250 1300 1350 1400 1450 1500 1550 1600 1650 1700 1750 1800 1850 1900 1950 2000 2050 2100 2150 2200 2250 2300 2350 2400 2450 2500 2550 2600 2650 2700 2750 2800 2850 2900 2950 3000 -2000 0 2000 4000 -1500 -1400 -1300 -1200 -1100 -1000 -900 -800 -700 -600 -500 -400 -300 -200 -100 0 100 200 300 400 500 600 700 800 900 1000 1100 1200 1300 1400 1500 1600 1700 1800 1900 2000 2100 2200 2300 2400 2500 2600 2700 2800 2900 3000 knife -2000 -1500 -1000 -500 0 500 1000 1500 2000 2500 3000 3500 -1500 -1450 -1400 -1350 -1300 -1250 -1200 -1150 -1100 -1050 -1000 -950 -900 -850 -800 -750 -700 -650 -600 -550 -500 -450 -400 -350 -300 -250 -200 -150 -100 -50 0 50 100 150 200 250 300 350 400 450 500 550 600 650 700 750 800 850 900 950 1000 1050 1100 1150 1200 1250 1300 1350 1400 1450 1500 1550 1600 1650 1700 1750 1800 1850 1900 1950 2000 2050 2100 2150 2200 2250 2300 2350 2400 2450 2500 2550 2600 2650 2700 2750 2800 2850 2900 2950 3000 -2000 0 2000 4000 -1500 -1400 -1300 -1200 -1100 -1000 -900 -800 -700 -600 -500 -400 -300 -200 -100 0 100 200 300 400 500 600 700 800 900 1000 1100 1200 1300 1400 1500 1600 1700 1800 1900 2000 2100 2200 2300 2400 2500 2600 2700 2800 2900 3000 gun -2000 -1500 -1000 -500 0 500 1000 1500 2000 2500 3000 3500 -1500 -1450 -1400 -1350 -1300 -1250 -1200 -1150 -1100 -1050 -1000 -950 -900 -850 -800 -750 -700 -650 -600 -550 -500 -450 -400 -350 -300 -250 -200 -150 -100 -50 0 50 100 150 200 250 300 350 400 450 500 550 600 650 700 750 800 850 900 950 1000 1050 1100 1150 1200 1250 1300 1350 1400 1450 1500 1550 1600 1650 1700 1750 1800 1850 1900 1950 2000 2050 2100 2150 2200 2250 2300 2350 2400 2450 2500 2550 2600 2650 2700 2750 2800 2850 2900 2950 3000 -2000 0 2000 4000 -1500 -1400 -1300 -1200 -1100 -1000 -900 -800 -700 -600 -500 -400 -300 -200 -100 0 100 200 300 400 500 600 700 800 900 1000 1100 1200 1300 1400 1500 1600 1700 1800 1900 2000 2100 2200 2300 2400 2500 2600 2700 2800 2900 3000 drown -2000 -1500 -1000 -500 0 500 1000 1500 2000 2500 3000 3500 -1500 -1450 -1400 -1350 -1300 -1250 -1200 -1150 -1100 -1050 -1000 -950 -900 -850 -800 -750 -700 -650 -600 -550 -500 -450 -400 -350 -300 -250 -200 -150 -100 -50 0 50 100 150 200 250 300 350 400 450 500 550 600 650 700 750 800 850 900 950 1000 1050 1100 1150 1200 1250 1300 1350 1400 1450 1500 1550 1600 1650 1700 1750 1800 1850 1900 1950 2000 2050 2100 2150 2200 2250 2300 2350 2400 2450 2500 2550 2600 2650 2700 2750 2800 2850 2900 2950 3000 -2000 0 2000 4000 -1500 -1400 -1300 -1200 -1100 -1000 -900 -800 -700 -600 -500 -400 -300 -200 -100 0 100 200 300 400 500 600 700 800 900 1000 1100 1200 1300 1400 1500 1600 1700 1800 1900 2000 2100 2200 2300 2400 2500 2600 2700 2800 2900 3000 hang -2000 -1500 -1000 -500 0 500 1000 1500 2000 2500 3000 3500 -1500 -1450 -1400 -1350 -1300 -1250 -1200 -1150 -1100 -1050 -1000 -950 -900 -850 -800 -750 -700 -650 -600 -550 -500 -450 -400 -350 -300 -250 -200 -150 -100 -50 0 50 100 150 200 250 300 350 400 450 500 550 600 650 700 750 800 850 900 950 1000 1050 1100 1150 1200 1250 1300 1350 1400 1450 1500 1550 1600 1650 1700 1750 1800 1850 1900 1950 2000 2050 2100 2150 2200 2250 2300 2350 2400 2450 2500 2550 2600 2650 2700 2750 2800 2850 2900 2950 3000 -2000 0 2000 4000 -1500 -1400 -1300 -1200 -1100 -1000 -900 -800 -700 -600 -500 -400 -300 -200 -100 0 100 200 300 400 500 600 700 800 900 1000 1100 1200 1300 1400 1500 1600 1700 1800 1900 2000 2100 2200 2300 2400 2500 2600 2700 2800 2900 3000 toxicgas -2000 -1500 -1000 -500 0 500 1000 1500 2000 2500 3000 3500 -1500 -1450 -1400 -1350 -1300 -1250 -1200 -1150 -1100 -1050 -1000 -950 -900 -850 -800 -750 -700 -650 -600 -550 -500 -450 -400 -350 -300 -250 -200 -150 -100 -50 0 50 100 150 200 250 300 350 400 450 500 550 600 650 700 750 800 850 900 950 1000 1050 1100 1150 1200 1250 1300 1350 1400 1450 1500 1550 1600 1650 1700 1750 1800 1850 1900 1950 2000 2050 2100 2150 2200 2250 2300 2350 2400 2450 2500 2550 2600 2650 2700 2750 2800 2850 2900 2950 3000 -2000 0 2000 4000 -1500 -1400 -1300 -1200 -1100 -1000 -900 -800 -700 -600 -500 -400 -300 -200 -100 0 100 200 300 400 500 600 700 800 900 1000 1100 1200 1300 1400 1500 1600 1700 1800 1900 2000 2100 2200 2300 2400 2500 2600 2700 2800 2900 3000 cookgas -2000 -1500 -1000 -500 0 500 1000 1500 2000 2500 3000 3500 -1500 -1450 -1400 -1350 -1300 -1250 -1200 -1150 -1100 -1050 -1000 -950 -900 -850 -800 -750 -700 -650 -600 -550 -500 -450 -400 -350 -300 -250 -200 -150 -100 -50 0 50 100 150 200 250 300 350 400 450 500 550 600 650 700 750 800 850 900 950 1000 1050 1100 1150 1200 1250 1300 1350 1400 1450 1500 1550 1600 1650 1700 1750 1800 1850 1900 1950 2000 2050 2100 2150 2200 2250 2300 2350 2400 2450 2500 2550 2600 2650 2700 2750 2800 2850 2900 2950 3000 -2000 0 2000 4000 -1500 -1400 -1300 -1200 -1100 -1000 -900 -800 -700 -600 -500 -400 -300 -200 -100 0 100 200 300 400 500 600 700 800 900 1000 1100 1200 1300 1400 1500 1600 1700 1800 1900 2000 2100 2200 2300 2400 2500 2600 2700 2800 2900 3000 poison Freq by Method

In [36]:
draw(SVG("myplot.svg", 14cm, 25cm), p)  # to save in other formats use pkg Cairo and Fontconfig.

In [37]:
# contour
volcano = convert(Array,(dataset("datasets","volcano")))


Out[37]:
87x61 Array{Int64,2}:
 100  100  101  101  101  101  101  100  …  106  106  105  105  104  104  103
 101  101  102  102  102  102  102  101     107  106  106  105  105  104  104
 102  102  103  103  103  103  103  102     107  107  106  106  105  105  104
 103  103  104  104  104  104  104  103     108  107  107  106  106  105  105
 104  104  105  105  105  105  105  104     108  107  107  107  106  106  105
 105  105  105  106  106  106  106  105  …  108  108  108  107  107  106  106
 105  106  106  107  107  107  107  106     109  109  108  108  107  107  106
 106  107  107  108  108  108  108  107     110  109  109  108  108  107  106
 107  108  108  109  109  109  109  108     110  110  109  109  108  107  107
 108  109  109  110  110  110  110  109     111  110  110  109  108  107  107
 109  110  110  111  111  111  111  110  …  112  111  110  109  108  107  106
 110  110  111  113  112  111  113  112     113  111  110  109  108  107  106
 110  111  113  115  114  113  114  114     114  112  110  109  108  107  105
   ⋮                        ⋮            ⋱         ⋮                        ⋮
 102  103  103  104  104  105  106  106  …   96   96   96   96   96   96   96
 101  102  103  103  104  105  105  106      96   96   96   96   96   96   96
 100  101  102  102  103  103  104  104      96   96   96   96   96   96   96
 100  101  101  102  102  103  103  104      96   96   96   96   96   96   95
  99  100  101  102  102  103  103  103      96   96   96   96   96   95   95
  99  100  100  101  101  102  102  102  …   95   95   95   95   95   95   95
  99  100  100  100  101  101  101  102      95   95   95   95   95   95   94
  99   99   99   99  100  100  101  101      95   94   94   94   94   94   94
  98   99   99   99   99  100  100  101      94   94   94   94   94   94   94
  98   98   98   99   99   99  100  100      94   94   94   94   94   94   94
  97   98   98   98   99   99   99  100  …   94   94   94   94   94   94   94
  97   97   97   98   98   99   99   99      94   94   94   94   94   94   94

In [38]:
plot(z=volcano, Geom.contour(levels=[110, 130, 150, 170, 190]))
# arguments(optional): levels: it could be either an array of contour levels, or the number of levels to plot.
# plot(z=volcano, Geom.contour(levels=5))
# plot(z=volcano, Geom.contour(levels=[110, 130, 150, 170, 190]))


Out[38]:
-125 -100 -75 -50 -25 0 25 50 75 100 125 150 175 200 225 -100 -95 -90 -85 -80 -75 -70 -65 -60 -55 -50 -45 -40 -35 -30 -25 -20 -15 -10 -5 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125 130 135 140 145 150 155 160 165 170 175 180 185 190 195 200 -100 0 100 200 -100 -90 -80 -70 -60 -50 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200 120 110 150 160 140 130 170 180 190 Color -100 -80 -60 -40 -20 0 20 40 60 80 100 120 140 160 180 -80 -75 -70 -65 -60 -55 -50 -45 -40 -35 -30 -25 -20 -15 -10 -5 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125 130 135 140 145 150 155 160 -100 0 100 200 -80 -75 -70 -65 -60 -55 -50 -45 -40 -35 -30 -25 -20 -15 -10 -5 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125 130 135 140 145 150 155 160

In [39]:
# contour also works for functions!!
plot(z=(x,y) -> x*exp(-(x-round(Int, x))^2-y^2), x=linspace(-8,8,150), y=linspace(-2,2,150), Geom.contour)


Out[39]:
x -35 -30 -25 -20 -15 -10 -5 0 5 10 15 20 25 30 35 -30 -29 -28 -27 -26 -25 -24 -23 -22 -21 -20 -19 -18 -17 -16 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 -40 -20 0 20 40 -30 -28 -26 -24 -22 -20 -18 -16 -14 -12 -10 -8 -6 -4 -2 0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 -10 0 -5 5 10 Color -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 -6.0 -5.8 -5.6 -5.4 -5.2 -5.0 -4.8 -4.6 -4.4 -4.2 -4.0 -3.8 -3.6 -3.4 -3.2 -3.0 -2.8 -2.6 -2.4 -2.2 -2.0 -1.8 -1.6 -1.4 -1.2 -1.0 -0.8 -0.6 -0.4 -0.2 0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0 2.2 2.4 2.6 2.8 3.0 3.2 3.4 3.6 3.8 4.0 4.2 4.4 4.6 4.8 5.0 5.2 5.4 5.6 5.8 6.0 -6 -3 0 3 6 -6.0 -5.5 -5.0 -4.5 -4.0 -3.5 -3.0 -2.5 -2.0 -1.5 -1.0 -0.5 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 y

Advantages and Disadvantages

Advantages

  1. Nice plots.
  2. Great to display data.

Disadvantages

  1. A bit slow.
  2. 3D graphs?
  3. ggplot2 is not completely implemented, e.g. there is no polar plots in Gadfly

References

[1] Gadfly Github page and this
[2] https://en.wikibooks.org/wiki/Introducing_Julia/Plotting
[3] The Grammar of Graphics (2005), Leland Wilkinson.
[4] ggplot2: Elegant Graphics for Data Analysis (2009), Hadley Wickham.
[5] ggplo2 Essentials (2015), Donato Teutonico.
[6] R graphics cookbook (2013), Winston Chang


In [ ]: