Univariate Graphs III Review Create histogram from Commands Window. Multipanel histogram. Quantile...

Post on 30-Dec-2015

233 views 2 download

Transcript of Univariate Graphs III Review Create histogram from Commands Window. Multipanel histogram. Quantile...

Univariate Graphs III

• Review

• Create histogram from Commands Window.

• Multipanel histogram.

• Quantile Plots

• Quantile-Normal Plots

• Quantile-Quantile Plots

Histogram from Commands

• From the Command Window typegraphsheet(height=6.4,width=7.5)hist(iris$sepal.length, nclass=10, xlab="sepal.length")

• Graphs from the Commands Window are fixed unless…

• Right click on the histogram and select Convert to Objects.

• Now you can change the axis scales, etc.

4 5 6 7 8

0

5

10

15

20

25

30

sepal.length

Multipanel Histogram

• In the Iris data window, select sepal.length and then CTRL select variety.

• Using the Graph->Multipanel menu, plot a Histogram.

• Note that under Conditioning Columns, the column list is variety

• Try changing the number of rows and columns in the layout to be 2 by 2

4.5 5.5 6.5 7.5

sepal.length

0

5

10

15

20

25

0

5

10

15

20

25

0

5

10

15

20

25

Setosa

Versicolor

Virginica

4.5 5.5 6.5 7.5

sepal.length

0

5

10

15

20

25

Setosa Versicolor

Virginica

Multipanel Histogram for Several Variables

• In the Iris data window, select sepal.width and then CTRL select variety.

• Using the Graph->Multipanel menu, plot a Histogram.

• Select the same Graphsheet as was used for the previous histogram

4.5 5.5 6.5 7.5sepal.length

01020

01020

01020

Setosa

Versicolor

Virginica

2.0 2.5 3.0 3.5 4.0 4.5sepal.width

01020

01020

01020

Setosa

Versicolor

Virginica

1.0 2.0 3.0 4.0 5.0 6.0 7.0petal.length

01020

01020

01020

Setosa

Versicolor

Virginica

0.1 0.5 0.9 1.3 1.7 2.1 2.5petal.width

0102030

0102030

0102030

Setosa

Versicolor

Virginica

4.5 5.5 6.5 7.5sepal.length

05

10152025

Setosa Versicolor

Virginica

2.0 2.5 3.0 3.5 4.0 4.5sepal.width

05

10152025

Setosa Versicolor

Virginica

1.0 2.5 4.0 5.5 7.0petal.length

05

10152025

Setosa Versicolor

Virginica

0.1 0.7 1.3 1.9 2.5petal.width

0

10

20

30Setosa Versicolor

Virginica

Quantile Plots

• A Quantile Plot graphs the value of each observation against the fraction of observations that are equal to or less than that observation

where i is the index of the observation in a sorted list from i = 1 to N

N

ifi

5.0−=

Quantile Plot of Sepal Length

graphsheet(height=6.4,width=6.4)

tLength <- length(iris$sepal.length)

plot(c(1:tLength)/tLength,

sort(iris$sepal.length),

xlab = "Fraction Value",

ylab="Sepal Length (cm)")

Quantile Plot of Sepal Length

graphsheet(height=6.4,width=6.4)

qqmath(~ sepal.length,

distribution=qunif, data=iris,

aspect=1,

xlab = "Fraction Value",

ylab="Sepal Length (cm)")

Quantile Plot of Sepal Length

graphsheet(height=4,width=7.5)

qqmath(~ sepal.length | variety,

distribution=qunif, data=iris,

panel = function(x, y) {

panel.grid()

panel.xyplot(x, y)

},

layout=c(3,1), aspect=1,

xlab = "Fraction Value",

ylab="Sepal Length (cm)")

Quantile-Normal PlotUsing Menus

• In the Iris data window, select sepal.length.

• Using the Graph->2D menu, select a Q-Q Plot.

• Right click on the graph, select Position/Size and then set the Aspect Ratio to 1.

-3 -2 -1 0 1 2 3

Normal Distribution

4

5

6

7

8

sepal.length

Quantile-Normal Plot

graphsheet(height=6.4,width=6.4)

qqnorm(iris$sepal.length, xlab = "Quantiles from Normal Distribution",

ylab = "Quantiles from Sample")

Quantile-Normal Trellis Plot

graphsheet(height=6.4,width=6.4)

qqmath(~ sepal.length,

distribution=qnorm, data=iris,

prepanel = prepanel.qqmathline,

panel = function(x, y) {

panel.qqmathline(y, distribution = qnorm)

panel.qqmath(x, y)

},

aspect=1,

xlab = "Normal Distribution",

ylab="Sepal Length (cm)")

Quantile-Normal Trellis Plot

graphsheet(height=6.4,width=6.4)

qqmath(~ sepal.length | variety,

distribution=qnorm, data=iris,

prepanel = prepanel.qqmathline,

panel = function(x, y) {

panel.qqmathline(y, distribution = qnorm)

panel.qqmath(x, y)

},

aspect=1, layout=c(2,2),

xlab = "Normal Distribution",

ylab="Sepal Length (cm)")

5

6

7

Setosa

-2 -1 0 1 2

Versicolor

5

6

7

Virginica

Normal Distribution

Sepal Length (cm)

Quantile-Quantile PlotUsing Menus

• In the Iris data window, select sepal.length.

• CTRL select petal.length

• Using the Graph->2D menu, select a Q-Q Plot.

• Right click on the graph, select Position/Size and then set the Aspect Ratio to 1.

0 2 4 6 8

sepal.length

0

2

4

6

8

petal.length

Quantile-Quantile Trellis Plot

graphsheet(height=6.4,width=6.4)

qq(variety ~ sepal.length, data=iris,subset = variety=="Setosa" | variety=="Versicolor",aspect=1)

For Thursday

• Read A Tour of Trellis Graphics pp 1-17 (download from the following web page)http://cm.bell-labs.com/cm/ms/departments/sia/project/trellis/software.writing.html

• Reaction papers are due October 3rd.