-
-
Notifications
You must be signed in to change notification settings - Fork 53
/
plottingQRef.Rmd
800 lines (534 loc) · 20.4 KB
/
plottingQRef.Rmd
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
---
title: "Plotting in R Quick Reference"
author: "Mark Niemann-Ross"
date: "`r Sys.Date()`"
output:
html_document:
df_print: paged
toc: yes
github_document:
toc: yes
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(lattice)
data("ChickWeight")
```
# About
## About This Document
This document provides brief explanations of the plotting functions available in Base R and the lattice package. It does not cover the [tidyverse or ggplot](https://rstudio.com/resources/cheatsheets/) - Rstudio does a great job of that without my help.
## Related Material
This Quick Reference is supplemental to courses on [LinkedIn Learning](https://www.linkedin.com/learning/r-for-data-science-lunchbreak-lessons/). A quick reference to [matrix math functions in R is here](http://niemannross.com/link/rmatrixqref). A quick reference to [clustering functions in R is here](http://niemannross.com/link/rclusterqref). An index to all R functions covered at LinkedIn Learning is found [here](http://niemannross.com/link/rindex). The latest version of this quick reference is found [here](http://niemannross.com/link/rplotqref). The source to this document is found on [github/mnr](https://github.com/mnr/R-for-Data-Science-Lunchbreak-Lessons). This document is available as Free Software under the terms of the [Free Software Foundation’s](http://www.gnu.org/) [GNU General Public License](https://www.r-project.org/COPYING).
## About Mark Niemann-Ross
[Mark](https://niemannross.com/) is an author for LinkedIn Learning and writes Science Fiction.
# plot
[Instructional video on plot()](https://linkedin-learning.pxf.io/plot)
The simplest of all plots
```{r, echo=TRUE}
plot(ChickWeight$Time,ChickWeight$weight)
```
Change the appearance of the plotted points
```{r, echo=TRUE}
plot(ChickWeight$Time,ChickWeight$weight,type = "l")
```
setting the titles and labels
```{r, echo=TRUE}
plot(ChickWeight$Time,ChickWeight$weight,
type = "l",
main = "Plot for R Example",
sub = "We are learning a little at a time",
xlab="number of days since birth",
ylab="grams of body weight")
```
add another line to a plot
```{r, echo=TRUE}
plot(ChickWeight$Time,ChickWeight$weight,
type = "l",
main = "Plot for R Example",
sub = "We are learning a little at a time",
xlab="number of days since birth",
ylab="grams of body weight")
lines(c(1,20),c(350,50))
```
change the appearance of the graph
```{r, echo=TRUE}
plot(ChickWeight$Time,ChickWeight$weight,
type = "l",
main = "Plot for R Example",
sub = "We are learning a little at a time",
xlab="number of days since birth",
ylab="grams of body weight")
lines(c(1,20),c(350,50), type="o", pch=22, lty=2, col="red")
```
You can also use functions as x and y arguments
```{r, echo=TRUE}
some.values <- function(my.something) {
return(seq(from=1, to=100,length.out = length(my.something))^2)
}
plot(mtcars$mpg,some.values(mtcars$mpg))
```
Here's a clever trick - put a plot in a function
```{r, echo=TRUE}
plotThis <- function(lineX,lineY) {plot(mtcars$mpg,
type = "b",
main = "Plot for R Example",
sub = "We are learning a little at a time",
xlab="mpg is Miles Per Gallon",
ylab="Look at the pretty bumps")
lines(lineX,lineY)
}
plotThis(c(5,30),c(15,30))
plotThis(c(15,30),c(25,5))
```
# conditional density plot
[Instructional video on cdplot()](https://linkedin-learning.pxf.io/rweekly_cdplot)
Suppose you are doing research: given a certain amount of time, how much should a chick weigh?
```{r echo=TRUE}
# because conditional density plots require a factor
ThreeWeights <- cut(ChickWeight$weight, 3, labels = c(34, 148, 260))
cdplot(ChickWeight$Time, ThreeWeights)
cdplot(ChickWeight$Time, ThreeWeights,
main = "How much should a chick weigh?",
ylab = "Probable Weight",
xlab = "Days"
)
# can you say "overplotting"
cdplot(factor(weight) ~ Time, data = ChickWeight)
# let's fix the overplot with cut()
cdplot(factor(cut(weight, 6, labels = 1:6 * 62)) ~ Time,
data = ChickWeight,
main = "How much should a chick weigh?",
ylab = "Weight",
xlab = "Days"
)
```
# boxplot
[Instructional video on boxplot()](https://linkedin-learning.pxf.io/rweekly_boxplot)
```{r, echo=TRUE}
boxplot(mtcars$mpg)
boxplot(mpg ~ cyl, data = mtcars, col = "lightgray", varwidth = TRUE,
main = "mpg vs cylinders",
ylab = "mpg",xlab = "cylinders")
# Here are the numbers used to create the boxplot
fivenum(mtcars$mpg)
```
# Histogram
[Instructional video on hist()](https://linkedin-learning.pxf.io/rweekly_histogram)
```{r, echo=TRUE}
hist(ChickWeight$weight)
hist(ChickWeight$weight, density = 30)
hist(ChickWeight$weight, density = 30, breaks = c(0,100,200,max(ChickWeight$weight)))
hist(ChickWeight$weight, breaks = fivenum(ChickWeight$weight))
```
# coplot
[Instructional video on coplot()](https://linkedin-learning.pxf.io/rweekly_coplot)
```{r, echo=TRUE}
coplot(ChickWeight$weight ~ ChickWeight$Time | ChickWeight$Diet)
coplot(weight ~ Time | Diet, data = ChickWeight)
coplot(weight ~ Time | Diet, data = ChickWeight, columns = 4)
coplot(weight ~ Time | Diet, data = ChickWeight,
panel = function(x,y,...) { abline(lm(y ~ x)) })
# further explanations:
# http://geog.uoregon.edu/GeogR/topics/coplots.html
```
# barplot
[Instructional video on barplot()](https://linkedin-learning.pxf.io/rweekly_barplot)
```{r, echo=TRUE}
fiveValues <- fivenum(ChickWeight$weight) # just to see what we're working with
barplot(fiveValues) # the simplest of bar plots
barplot(height = fiveValues,
names.arg = fivenum(ChickWeight$weight),
horiz = TRUE,
col = fiveValues,
main = "Range for Chick Weights"
)
```
# piechart
[Instructional video on pie()](https://linkedin-learning.pxf.io/rweekly_piechart)
```{r, echo=TRUE}
# simple example of a pie chart
pie(table(ChickWeight$Diet))
# same pie chart with labeled segments
pie(table(ChickWeight$Diet),labels = c("horsebean","linseed","soybean", "sunflower"))
# same pie chart, labeled and with gradients instead of colors
pie(table(ChickWeight$Diet),
labels = c("horsebean","linseed","soybean", "sunflower"),
density = 10*1:4,
angle = 100*1:4)
```
# spineplot
[Instructional video on spineplot()](https://linkedin-learning.pxf.io/rweekly_spineplot)
```{r, echo=TRUE}
# width of bars = frequency of X
# height of bars = frequency of y
# Y must be a factor and is the dependent variable
spineplot(ChickWeight$weight, ChickWeight$Diet) # spineplot(x,y)
# interesting observations
# Height of bars indicates obs per diet. Diet 1 has more obs
# Width of bars indicates obs per weight. More chicks are weighed between 50 and 100
# or...
spineplot(Diet ~ weight, data = ChickWeight) # spineplot(y ~ x)
# bells and whistles
spineplot(Diet ~ weight,
data = ChickWeight,
breaks = fivenum(ChickWeight$weight),
col = c(5:8),
xlab = "Chicken Weight",
ylab = "Chicken Diet")
# The above is actually a spinogram - like a histogram
# example of a true spine plot. Both x and y must be factors
spineplot(Diet ~ factor(weight),
data = ChickWeight,
col = c(5:8))
spineplot(factor(weight) ~ Diet,
data = ChickWeight,
col = c(1:nlevels(factor(ChickWeight$weight))))
# subset of data
# use the 1st half of data. Would make sense to have a more sophisticated selection
spineplot(Diet ~ factor(weight),
data = ChickWeight,
subset = c(1:(578/2)),
drop.unused.levels = TRUE,
col = c(4:7)
)
```
# dotchart
[Instructional video on dotchart()](https://linkedin-learning.pxf.io/rweeklydotchart)
```{r, echo=TRUE}
# dotchart works with matrix or vector (not dataframe)
# Dotplot for vectors ----
vectorToPlot <- c(1:6)
names(vectorToPlot) <- c(LETTERS[1:6])
dotchart(vectorToPlot, cex = .7)
myGroup <- factor(c("group1","group3","group2","group1","group3","group2"))
dotchart(vectorToPlot, groups = myGroup)
dotchart(vectorToPlot,
gcolor = "red", groups = myGroup,
gdata = c(median(vectorToPlot[myGroup == "group1"]),
median(vectorToPlot[myGroup == "group2"]),
median(vectorToPlot[myGroup == "group3"])),
cex = .7,
main = "Groups of Things", xlab = "Things")
# dotplot for matrix ----
str(WorldPhones) # worldphones is a matrix - not a dataframe
# Major labels (Groups) are matrix columns. Minor labels are matrix rows
dotchart(WorldPhones) # works, but it's messy
dotchart(WorldPhones, gcolor = "Blue", cex = .5,
gdata = colMeans(WorldPhones), gpch = 15,
main = "World Phones by Country")
```
# fourfoldplot
[Instructional video on fourfoldplot()](https://linkedin-learning.pxf.io/rweekly_fourfoldplot)
```{r, echo=TRUE}
# Basic Idea ----
matrixOfData <- matrix(c(2,4,8,32), nrow = 2, ncol = 2,
dimnames = list(c("Chickens","Fish"), c("Big","Small")))
fourfoldplot(matrixOfData)
fourfoldplot(matrixOfData, conf.level = .5, space = .25)
# Compare more than a matrix ----
arrayOfData <- array(seq(from = 1, by = 134, length.out = 12),
dim = c(2,2,3),
dimnames = list(c("Chickens","Fish"), c("Big","Small")))
fourfoldplot(arrayOfData, conf.level = .95, color = c("red","green"),
std = "all.max",
main = "Chicken vs Fish",
mfrow = c(1,3))
```
# matplot
[Instructional video on matplot()](https://linkedin-learning.pxf.io/rweek_matplot)
```{r, echo=TRUE}
# first create some sample matrix
matrix1 <- matrix(c(1:8,1:8), nrow = 8, ncol = 2 )
matrix2 <- matrix(sample(1:16, 16), nrow = 8, ncol = 2)
devAskNewPage(ask = FALSE) # turns off interactive
# then plot. Plots 1st column of 1st matrix against 2nd column of 2nd matrix
matplot(matrix1, matrix2)
matplot(matrix1, matrix2, type = "l")
matplot(matrix1, matrix2, type = "ls") # other types: p, o, b, h, s
matplot(matrix1, matrix2, type = "ls",
lty = c(5,6), lwd = c(3,10), lend = c(.1,.3))
#adding a second line
matplot(matrix1, matrix2)
matlines(matrix(c(1:16), nrow = 8, ncol = 2),
matrix(c(15:0), nrow = 8, ncol = 2))
```
# mosaicplot
[Instructional video on mosaicplot()](https://linkedin-learning.pxf.io/rweekly_mosaicplot)
```{r, echo=TRUE}
# build an array for demonstration
sample1 <- as.integer(runif(10, min = 1, max = 30))
sample2 <- c(10:1)
sample3 <- sample(1:30, 10)
AnimalPlanet <- array(c(sample1, sample2, sample3),
dim = c(2,5,3),
dimnames = list(
"Planet" = c("Earth", "Mars"),
"weight" = c("Featherweight", "Light", "Normal", "Medium", "Heavy" ),
"animals" = c("Chickens", "Fish", "Pigs")
)
)
mosaicplot(AnimalPlanet)
# playin with options
mosaicplot(AnimalPlanet, shade = TRUE)
mosaicplot(AnimalPlanet, shade = fivenum(AnimalPlanet))
mosaicplot(AnimalPlanet, shade = TRUE, sort = c(3,2,1))
mosaicplot(AnimalPlanet, shade = TRUE, off = c(20,15,20))
mosaicplot(AnimalPlanet, shade = TRUE, dir = c("h","v","h"))
mosaicplot(AnimalPlanet, color = TRUE)
mosaicplot(AnimalPlanet, color = c("red","green","blue"))
mosaicplot(AnimalPlanet, cex.axis = .5)
mosaicplot(AnimalPlanet, las = 1) # 0, 1, 2, 3
mosaicplot(AnimalPlanet, type = "f")
# also uses ~ for formula substitution
```
# stemplot
[Instructional video on stem()](https://linkedin-learning.pxf.io/rweekly_stemplot)
```{r, echo=TRUE}
sample1 <- rnorm(100, mean = 10, sd = 3) # creates a normal distribution (bell curve)
sample1 # difficult to parse this data
# doesn't clearly indicate anything
plot(sample1)
stem(sample1) # demonstrates a normal curve
stem(sample1, scale = 2)
```
# stripchart
[Instructional video on stripchart()](https://linkedin-learning.pxf.io/rweekly_stripchart)
```{r, echo=TRUE}
sample1 <- rnorm(100, mean = 10, sd = 3) # creates a normal distribution (bell curve)
stripchart(sample1)
# labeled multiple strip charts
sample2 <- c(10:1)
sample3 <- sample(1:30, 10)
stripchart(list("Apples" = sample1, "Bananas" = sample2, "Coconuts" = sample3) )
# using the "~" formula
groupFactor <- factor(rep(c("Red", "Blue", "Yellow", "Red"), 25)) # set up a factor
stripchart(sample1 ~ groupFactor)
stripchart(sample1 ~ groupFactor, group.names = c("R", "B", "Y"))
# other
stripchart(sample1, method = "jitter", jitter = 1)
stripchart(sample1, vertical = TRUE)
```
# sunflower
[Instructional video on sunflowerplot()](https://linkedin-learning.pxf.io/rweekly_sunflower)
```{r, echo=TRUE}
xpos <- c(1,2,3,3,1,2,3,1,2,3,4,5,6) # 13 xy points
ypos <- c(1,1,1,1,1,1,1,1,1,1,1,1,1)
# but only 6 points are plotted
plot(xpos, ypos)
# sunflowerplot will show duplicates and the extent they are duplicated
# use xyTable to calculate overlapping points
xyTbl <- xyTable(xpos, ypos)
# then use sunflowerplot to show the overlap at each point
sunflowerplot(xyTbl)
```
# xyplot
[Instructional video on xyplot()](https://linkedin-learning.pxf.io/rweeklatticexyplot)
Part of the lattice package
```{r, echo=TRUE}
# xyplot is an important place to start - all attributes are defined in this help file.
# so easy to set up plots once you understand formulas
xyplot(weight ~ Time, data = ChickWeight)
xyplot(weight*3 ~ Time, data = ChickWeight)
xyplot(weight ~ Time | Diet, data = ChickWeight)
# what if you want to add two variables instead of combine graphs?
ChickWeight$anotherVar <- 1:nrow(ChickWeight) # add a variable
# not what we want
xyplot(weight ~ Time + anotherVar, type = "l", data = ChickWeight)
# use I() (inhibit interpretation) to get desired result
xyplot(weight ~ I(Time + anotherVar), type = "l", data = ChickWeight)
# lots of options for creating keys/legends
xyplot(weight ~ Time | Diet,
data = ChickWeight,
type = "a", # lines = average
groups = Diet, # necessary for auto.key,
auto.key = list(columns = 2,
points = FALSE,
rectangles = TRUE,
space = "bottom"))
# or just use autokey
xyplot( weight ~ Time,
groups = Diet,
data = ChickWeight,
type = "l",
auto.key = TRUE)
```
# cloud and wireframe
[Instructional video on cloud()](https://linkedin-learning.pxf.io/rweeklycloudplot)
Part of the lattice package
```{r, echo=TRUE}
# clouds and wireframes "look" the same...but
# I need a third numeric variable
ChickWeight$ascend <- 1:nrow(ChickWeight)
names(ChickWeight) # review names of columns
cloud( weight ~ Time * ascend, data = ChickWeight)
# labeling axis
cloud( weight ~ Time * Diet,
data = ChickWeight,
scales = list(arrows = FALSE))
# wireframe focused on comparing two variables against a third
wireframe( weight ~ Time * Diet, data = ChickWeight)
# also can be done with a matrix
mymatrix <- matrix(1:10000, nrow = 100)
wireframe(mymatrix)
# ooh - fancy!
wireframe(mymatrix,
shade = TRUE,
light.source = c(10,0,10),
drape = TRUE
)
# more parameters in xyplot and wireframe documentation
```
# level and contour
[Instructional video on levelplot() and contourplot()](https://linkedin-learning.pxf.io/rweeklycontourplot)
Part of the lattice package
```{r, echo=TRUE}
names(ChickWeight) # review names of columns
# using exact same setup as cloud and wireframe
levelplot( weight ~ Time * Diet, data = ChickWeight)
levelplot( weight ~ Time * Diet, data = ChickWeight, contour=TRUE) # adds lines
levelplot( weight ~ Time * Diet, data = ChickWeight, cuts=7) # default cuts = 15
contourplot( weight ~ Time * Diet, data = ChickWeight)
contourplot( weight ~ Time * Diet, data = ChickWeight, region=TRUE) # adds levels
contourplot( weight ~ Time * Diet, data = ChickWeight, labels = FALSE) # removes labels from lines
contourplot( weight ~ Time * Diet, data = ChickWeight, cuts=30)
```
# barchart
[Instructional video on barchart()](https://linkedin-learning.pxf.io/rweeklybarchart)
Part of the lattice package
```{r, echo=TRUE}
# barchart using standard formula setup
barchart( weight ~ Time + Diet, data = ChickWeight)
barchart( Diet ~ weight, data = ChickWeight) # these plots make more sense with a factor
# With barchart options
barchart( weight ~ Time + Diet, data = ChickWeight)
barchart( weight ~ Time + Diet, data = ChickWeight, box.ratio = 10)
barchart( weight ~ Time + Diet, data = ChickWeight, horizontal = TRUE) # note the axis stay the same
```
# bwplot
[Instructional video on bwplot()](https://linkedin-learning.pxf.io/rweeklybarchart)
```{r, echo=TRUE}
bwplot( Diet ~ Time, data = ChickWeight)
# with bwplot options
bwplot( Diet ~ Time, data = ChickWeight, box.ratio = 10)
bwplot( Diet ~ Time, data = ChickWeight,
notch = TRUE, varwidth = TRUE
)
# changing axis label
levels(ChickWeight$Diet) <- c("Apples","Bananas","Steak","Potatoes")
bwplot( Diet ~ Time, data = ChickWeight)
```
# splom
[Instructional video on splom()](https://linkedin-learning.pxf.io/rweeklysplom)
Part of the lattice package
SPLOM == Scatter PLot Matrices
```{r, echo=TRUE}
splom(ChickWeight)
splom(ChickWeight[1:2]) # plots weight & time
splom(~ChickWeight[1:2],
groups = Diet,
data = ChickWeight)
# smooths out the scatter plot
splom(~ChickWeight[1:2],
groups = Diet,
data = ChickWeight,
panel = panel.smoothScatter )
# colorful - but is it useful?
parallelplot(~ChickWeight[1:2],
groups = Diet,
data = ChickWeight)
```
# panels
[Instructional video on lattice panels](https://linkedin-learning.pxf.io/rweekpanels)
Part of the lattice package
```{r, echo=TRUE}
# changing graph to smoothscatter plot
splom(~ChickWeight[1:2],
groups = Diet,
data = ChickWeight,
panel = panel.smoothScatter)
# other panel options
splom(~ChickWeight[1:2],
data = ChickWeight,
panel = panel.loess)
splom(~ChickWeight[1:2],
data = ChickWeight,
panel = panel.spline)
# change bwplot to a violin plot
bwplot( Diet ~ Time, data = ChickWeight,
panel = function(..., box.ratio) {
panel.violin(..., col = "transparent",
varwidth = TRUE, box.ratio = box.ratio)
panel.bwplot(..., fill = NULL, box.ratio = .1)
}
)
# combine panels
someColors <- colorRampPalette(c("yellow","blue"))
# create a function to be used with panels
# look up ?panel for more options
myPanelFunc <- function(x,y,..){
panel.smoothScatter(x,y, lwd = 1, colramp = someColors)
panel.loess(x,y, lwd = 2, col = "red")
}
#...then set panel = to the panel plotting function
splom(~ChickWeight[1:2],
groups = Diet,
data = ChickWeight,
panel = myPanelFunc
)
# list of plot types and possible panels
# barchart: panel.barchart
# bwplot: panel.bwplot, panel.violin
# cloud : panel.cloud, panel.3dscatter, panel.3dwire, panel.wireframe
# contourplot: panel.contourplot, panel.levelplot, panel.levelplot.raster
# densityplot: panel.densityplot
# dotplot: panel.dotplot
# generics: panel.abline, panel.arrows, panel.average, panel.axis, panel.curve,
# panel.fill, panel.functions, panel.grid, panel.linejoin, panel.lines
# panel.lmline, panel.loess, panel.mathdensity, panel.points, panel.polygon,
# panel.refline, panel.rug, panel.smoothscatter, panel.violin
# histogram: panel.histogram
# levelplot: panel.contourplot, panel.levelplot, panel.levelplot.raster
# parallel: panel.parallel
# qqmath: panel.qqmath, panel.qqmathline
# stripplot: panel.stripplot
# xyplot: panel.xyplot, panel.qq, panel.splom
```
# strip plot
[Instructional video on stripplot()](https://linkedin-learning.pxf.io/rweekstripplot)
Part of the lattice package
```{r, echo=TRUE}
# simple plot. Pay attention to formula factor~numeric
stripplot( Diet ~ weight , data = ChickWeight)
# with panel.stripplot options
# note these can be passed without using panel.stripplot()
# jitter
stripplot( Diet ~ weight , data = ChickWeight,
jitter.data = TRUE
)
stripplot( Diet ~ weight , data = ChickWeight,
jitter.data = TRUE,
factor = 1
)
stripplot( Diet ~ weight , data = ChickWeight,
jitter.data = TRUE,
factor = .5
)
stripplot( Diet ~ weight , data = ChickWeight,
jitter.data = TRUE,
amount = .2 # similar to factor
)
# groups
stripplot( Diet ~ weight , data = ChickWeight,
jitter.data = TRUE,
factor = 1,
groups = Diet
)
# not what we want
stripplot( Diet ~ weight , data = ChickWeight,
horizontal = FALSE
)
# Need to also change the formula
stripplot( weight ~ Diet , data = ChickWeight,
horizontal = FALSE
)
```