Graphics Flashcards
1
Q
plot()
A
- Function in base R t hat is the most important high level function.
- First argument is data, usually a vector, but could be a data frame.
- Second argument can also be data, but could also be almost anything.
2
Q
plot() a data frame
A
- plot(data) gives a scatterplot matrix.
3
Q
plot() two vectors
A
- plot(x_variable or x_dataframe_column, y_variable or y_dataframe_column).
- Implies “y as a function of x”.
4
Q
par(mfrow=c())
A
- Function nested that will essentially create spaces in an imaginary matrix in which to fill in with plots and graphs.
- Determines how many graphics will appear in a single plot window.
5
Q
par()
A
- Function to examine the default graphical settings.
6
Q
Colors
A
- 657 base colors in R.
1) col=
2) fg =
3) bg =
4) col.main =
5) col.axis = - When putting colors in the arugments using the c() function, must have parantheses, be all lower case, and be surrounded by quotations.
7
Q
col =
A
- Option used for the colors of lines, symbols and text.
8
Q
fg =
A
- Option used for colors of axes and borders.
9
Q
bg =
A
- Option used for the color of the background or fill.
10
Q
col.main =
A
- Option used for the color for the plot title.
11
Q
col.axis =
A
- Option used for the color for the axis labels.
12
Q
lty =
A
- Option that controls the appearance of lines on a plot.
- Values 1 - 6 are used to create different line styles.
13
Q
lwd =
A
- Option that controls the line thickness.
- Defaults to 1 + lwd = 2 is twice as thick as default, lwd = 3 is three times as thick, etc.
14
Q
ps =
A
- Option that controls the absolute font size setting.
- Default is 16.
15
Q
cex =
A
- Option that controls character expansion = size of the text.
- Multiplier and default is 1.
- Final font specification is ps * cex.
- Can also affect plot symbols.
16
Q
cex.axis =
A
- Option that controls the text draw as tick labels.
17
Q
cex.lab =
A
- Option that controls the text of the axis labels.
18
Q
cex.main =
A
- Option that controls the text of the title.
19
Q
cex.sub =
A
- Option that controls the text of the subtitle.
20
Q
pch =
A
- Option that changes the plot symbol.
- Values are between 0 and 25.
21
Q
Barplot
A
- Displays the frequency or relative frequency for all observations of a categorical variable.
- Can be displayed horizontally or vertically.
- Can be grouped or stacked.
22
Q
Barplot Syntax
A
- barplot(height, width = 1, space = NULL, names.arg = NULL, legend.text = NULL, beside = FALSE, horiz = FALSE, density = NULL, angle = 45, col = NULL, border = par(“fg”), main = NULL, sub = NULL, xlab = NULL, ylab = NULL, xlim = NULL, ylim = NULL, xpd = TRUE, log = “”, axes = TRUE, axisnames = TRUE, cex.axis = par(“cex.axis”), cex.names = par(“cex.axis”),
inside = TRUE, plot = TRUE, axis.lty = 0, offset = 0, add = FALSE, args.legend = NULL, …)
23
Q
names.arg =
A
- Option that allows us to change the default names.
24
Q
Histograms
A
- Total area under the histogram totals to 1.0 and is directly comparable to the estimates of its probability density function.
- Can create using the hist() function.
25
truehist()
- Function in package MASS that produces a more accurate histogram than hist().
26
hist() syntax
- Example: hist(rivers, main = "hist(rivers)", freq = FALSE, col = "cyan", xlab = "miles").
27
Mosaicplot
- A graphical representation of the two-way frequency table of Contingency Table.
28
cor()
- Function that generate a correlation matrix from a data frame.
29
pair()
- Function that creates a scatterplot matrix.
| - Can be used on a matrix or data frame.
30
boxplot()
- Function that is used to depict groupings of numerical data through their five-number summaries.
- Will indicate which observations might be considered outliers.
- Can draw horizontally or vertically.
- Can operate on a single vector of values but usually two or more vectors make better use of the data.
31
Mapping in R
- Utilizes packages maps and mapdata.
32
ggplot()
- Function that is used to initialize the basic graph structure which layers can then be added to.
- Easier to make complicated graphics, difficult to make simple graphics.
33
ggplot() syntax
```
- ggplot(data = ,
aes(x = ,
y = ,
... ),
... ) +
- ggplot uses a "+" to separate layers.
```
34
aes
- A feature of ggplot that is something you can see.
- Includes position (on the x and y axes), color ("outside" color), fill ("inside" color), shape (of points), linetype and size.
35
Geoms
- A feature of ggplot that is used to describe the type of plot you want to produce.
36
Scaling
- Part of ggplot2 = tells ggplot what aesthetics to use when mapping.
37
Faceting (Grids)
- Subsetting in ggplot2.
| - Create separate graphs for subsets of data.
38
facet_wrap()
- Function in ggplot2 that defines subsets as the levels of a single grouping variable.
39
facet_grid()
- Function in ggplot2 that defines subsets as the crossing of two grouping variables.
40
Building a ggplot
- Need at least a base with the ggplot() function, a data from and a geom layer.