The best way is to download the data file and save it into a local folder

Then you can read it as much as you like

November 26, 2019

The best way is to download the data file and save it into a local folder

Then you can read it as much as you like

The commands in this page produce the plots of the following page

plot(survey$height_cm, main="1") plot(survey$height_cm, main="2", col="red") plot(survey$height_cm, main="3", cex=2) plot(survey$height_cm, main="4", cex=0.5) plot(survey$height_cm, main="5", pch=16) plot(survey$height_cm, main="6", pch=".")

The commands in this page produce the plots of the following page

plot(survey$height_cm, main="1", type = "l") plot(survey$height_cm, main="2", type = "o") plot(survey$height_cm, main="3", type = "b") plot(survey$height_cm, main="4", type = "p") plot(survey$height_cm, main="5", xlim=c(1,20)) plot(survey$height_cm, main="6", xlim=c(30,51))

plot(survey$height_cm, ylim=c(0,200)) points(survey$weight_kg, pch=2)

plot(survey$height_cm, type="l", ylim=c(0,200)) lines(survey$weight_kg, col="red")

plot(survey$height_cm, col=survey$Gender) legend("topleft", legend=c("Female", "Male"), fill=c(1,2))

plot(survey$height_cm) abline(h=mean(survey$height_cm), col="red", lwd=5)

This command adds a straight line in a specific position

`abline(h=1)`

adds a horizontal line in 1`abline(v=2)`

adds a vertical line in 2`abline(a=3, b=4)`

adds an \(y=a +b\cdot x\) line`a`

is the*intercept*when \(x=0\)`b`

is the*slope*

plot(survey$height_cm) abline(v=20, col="blue") abline(a=160, b=0.5)

plot(survey$height_cm, survey$weight_kg)

plot(survey$height_cm, survey$hand_span_cm)

Instead of

plot(survey$height_cm, survey$weight_kg)

we can write

plot(survey$weight_kg ~ survey$height_cm)

or even

plot(weight_kg ~ height_cm, data = survey)

plot(height_cm ~ hand_span_cm, data = survey) plot(height_cm ~ hand_span_cm, data = survey, subset = Gender=="Female") plot(height_cm ~ hand_span_cm, data = survey, subset = Gender=="Male")

It is easier to specify the *data.frame* and *which values* to plot

plot(height_cm ~ weight_kg, data=survey)

survey$handness <- as.factor(survey$handness) plot(Gender ~ handness, data=survey)

plot(Gender ~ weight_kg, data=survey)

plot(weight_kg ~ Gender, data=survey)

Plotting a numeric value depending on a factor results in a **boxplot**

It is a graphical version of `summary()`

.

- The center is the
**median** - The box is between the
*first*and*third*quartile (50% of cases) - The
*whiskers*extend a prediction of 95% of cases - Points are
**outliers**

plot(weight_kg ~ Gender, data=survey, boxwex=0.3, notch=TRUE, col="grey")

plot(survey)

`plot()`

can be used with one or two vectors, or with a formula`plot(y ~ x)`

looks like`plot(x, y)`

- Formulas are nice:
`plot(y~x, data=dframe)`

is better than`plot(dframe$x, dframe$y)`

- In general the defaults are good
- axis labels are the names of the variables being plotted
- ranges are automatic

- You can use numbers to choose colors, symbols and sizes of points
- You can choose the ranges, labels and

The figure type depends on the data type of the vector

- numeric: similar to
`points()`

or`lines()`

- factor: count frequency and draws
`barplot()`

- numeric v/s factor: same as
`boxplot()`

- complete data frame: same as
`pairs()`

- factor v/s factor: like a histogram in 2D

- The
`plot()`

command defines the ranges, labels and title - You can add more elements over a pre-existing plot:
`points()`

,`lines()`

`text()`

`segment()`

,`arrows()`

,`rect()`

,`polygon()`

`xspline()`

`legend()`

Learn more on the help page of each command

Colors can be specified in several ways:

- A numeric value is an index into a palette
- A character with a color name in English
- such as “red” or “steelblue”

- A character with a hexadecimal code
- such as “#A11F1F”
- Google “hexadecimal colors” to learn more