Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 135 lines (95 sloc) 5.002 kB
d3ee17b @wch Move and modify visual tests
wch authored
1 vcontext("dotplot")
2
b3b8fc6 @wch dotplot: add tests
wch authored
3 set.seed(112)
4 dat <- data.frame(x=rnorm(20), g=LETTERS[1:2])
5
6 # Basic dotplot with binning along x axis
d3ee17b @wch Move and modify visual tests
wch authored
7 ggplot(dat, aes(x)) + geom_dotplot(binwidth=.4)
8 save_vtest("basic dotplot with dot-density binning, binwidth=.4")
b3b8fc6 @wch dotplot: add tests
wch authored
9
d3ee17b @wch Move and modify visual tests
wch authored
10 ggplot(dat, aes(x)) + geom_dotplot(binwidth=.4, method="histodot")
11 save_vtest("histodot binning (equal bin spacing)")
b3b8fc6 @wch dotplot: add tests
wch authored
12
1b2b623 @wch Minor tweaks to tests
wch authored
13 ggplot(dat, aes(x)) + geom_dotplot(binwidth=.4, stackratio=.5, fill="white")
14 save_vtest("dots stacked closer: stackratio=.5, fill=white")
b3b8fc6 @wch dotplot: add tests
wch authored
15
1b2b623 @wch Minor tweaks to tests
wch authored
16 ggplot(dat, aes(x)) + geom_dotplot(binwidth=.4, dotsize=1.4, fill="white")
17 save_vtest("larger dots: dotsize=1.5, fill=white")
b3b8fc6 @wch dotplot: add tests
wch authored
18
19
20 # Stacking methods
d3ee17b @wch Move and modify visual tests
wch authored
21 ggplot(dat, aes(x)) + geom_dotplot(binwidth=.4, stackdir="up")
22 save_vtest("stack up")
b3b8fc6 @wch dotplot: add tests
wch authored
23
d3ee17b @wch Move and modify visual tests
wch authored
24 ggplot(dat, aes(x)) + geom_dotplot(binwidth=.4, stackdir="down")
25 save_vtest("stack down")
b3b8fc6 @wch dotplot: add tests
wch authored
26
d3ee17b @wch Move and modify visual tests
wch authored
27 ggplot(dat, aes(x)) + geom_dotplot(binwidth=.4, stackdir="center")
28 save_vtest("stack center")
b3b8fc6 @wch dotplot: add tests
wch authored
29
d3ee17b @wch Move and modify visual tests
wch authored
30 ggplot(dat, aes(x)) + geom_dotplot(binwidth=.4, stackdir="centerwhole")
31 save_vtest("stack centerwhole")
b3b8fc6 @wch dotplot: add tests
wch authored
32
33
34 # Stacking methods with coord_flip
d3ee17b @wch Move and modify visual tests
wch authored
35 ggplot(dat, aes(x)) + geom_dotplot(binwidth=.4, stackdir="up") + coord_flip()
36 save_vtest("stack up with coord_flip")
b3b8fc6 @wch dotplot: add tests
wch authored
37
d3ee17b @wch Move and modify visual tests
wch authored
38 ggplot(dat, aes(x)) + geom_dotplot(binwidth=.4, stackdir="down") + coord_flip()
39 save_vtest("stack down with coord_flip")
b3b8fc6 @wch dotplot: add tests
wch authored
40
d3ee17b @wch Move and modify visual tests
wch authored
41 ggplot(dat, aes(x)) + geom_dotplot(binwidth=.4, stackdir="center") + coord_flip()
42 save_vtest("stack center with coord_flip")
b3b8fc6 @wch dotplot: add tests
wch authored
43
d3ee17b @wch Move and modify visual tests
wch authored
44 ggplot(dat, aes(x)) + geom_dotplot(binwidth=.4, stackdir="centerwhole") + coord_flip()
45 save_vtest("stack centerwhole with coord_flip")
b3b8fc6 @wch dotplot: add tests
wch authored
46
47
48 # Binning along x, with groups
d3ee17b @wch Move and modify visual tests
wch authored
49 ggplot(dat, aes(x, fill=g)) + geom_dotplot(binwidth=.4, alpha=.4)
50 save_vtest("multiple groups, bins not aligned")
b3b8fc6 @wch dotplot: add tests
wch authored
51
52 ggplot(dat, aes(x, fill=g)) +
d3ee17b @wch Move and modify visual tests
wch authored
53 geom_dotplot(binwidth=.4, alpha=.4, binpositions="all")
54 save_vtest("multiple groups, bins aligned")
b3b8fc6 @wch dotplot: add tests
wch authored
55
56
57 # Binning along y axis
58 ggplot(dat, aes(x=0, y=x)) +
d3ee17b @wch Move and modify visual tests
wch authored
59 geom_dotplot(binwidth=.4, binaxis="y", stackdir="center")
60 save_vtest("bin along y, stack center")
b3b8fc6 @wch dotplot: add tests
wch authored
61
62 ggplot(dat, aes(x=0, y=x)) +
d3ee17b @wch Move and modify visual tests
wch authored
63 geom_dotplot(binwidth=.4, binaxis="y", stackdir="centerwhole")
64 save_vtest("bin along y, stack centerwhole")
b3b8fc6 @wch dotplot: add tests
wch authored
65
66 ggplot(dat, aes(x=0, y=x)) +
d3ee17b @wch Move and modify visual tests
wch authored
67 geom_dotplot(binwidth=.4, binaxis="y", stackdir="centerwhole", method="histodot")
68 save_vtest("bin along y, stack centerwhole, histodot")
b3b8fc6 @wch dotplot: add tests
wch authored
69
70
71 # Binning along y, with multiple grouping factors
72 dat2 <- data.frame(x=LETTERS[1:3], y=rnorm(90), g=LETTERS[1:2])
73
74 ggplot(dat2, aes(x=x, y=y)) +
d3ee17b @wch Move and modify visual tests
wch authored
75 geom_dotplot(binwidth=.25, binaxis="y", stackdir="centerwhole")
76 save_vtest("bin y, three x groups, stack centerwhole")
b3b8fc6 @wch dotplot: add tests
wch authored
77
78 ggplot(dat2, aes(x=x, y=y)) +
79 geom_dotplot(binwidth=.25, binaxis="y", stackdir="center", binpositions="all") +
d3ee17b @wch Move and modify visual tests
wch authored
80 save_vtest("bin y, three x groups, bins aligned across groups")
b3b8fc6 @wch dotplot: add tests
wch authored
81
82 ggplot(dat2, aes(x=x, y=y)) +
83 geom_dotplot(binwidth=.25, binaxis="y", stackdir="center", binpositions="all") +
84 coord_flip() +
d3ee17b @wch Move and modify visual tests
wch authored
85 save_vtest("bin y, three x groups, bins aligned, coord_flip")
b3b8fc6 @wch dotplot: add tests
wch authored
86
87 ggplot(dat2, aes(x="foo", y=y, fill=x)) + scale_y_continuous(breaks=seq(-4,4,.4)) +
d3ee17b @wch Move and modify visual tests
wch authored
88 geom_dotplot(binwidth=.25, position="dodge", binaxis="y", stackdir="center")
89 save_vtest("bin y, dodged")
b3b8fc6 @wch dotplot: add tests
wch authored
90
91 ggplot(dat2, aes(x="foo", y=y, fill=x)) + scale_y_continuous(breaks=seq(-4,4,.4)) +
92 geom_dotplot(binwidth=.25, position="dodge", binaxis="y", stackdir="center") +
d3ee17b @wch Move and modify visual tests
wch authored
93 coord_flip()
94 save_vtest("bin y, dodged, coord_flip")
95
b3b8fc6 @wch dotplot: add tests
wch authored
96
97 ggplot(dat2, aes(x=x, y=y, fill=g)) + scale_y_continuous(breaks=seq(-4,4,.4)) +
d3ee17b @wch Move and modify visual tests
wch authored
98 geom_dotplot(binwidth=.2, position="dodge", binaxis="y", stackdir="center")
99 save_vtest("bin y, three x groups, fill and dodge")
b3b8fc6 @wch dotplot: add tests
wch authored
100
101 ggplot(dat2, aes(x=as.numeric(x), y=y, group=x)) +
d3ee17b @wch Move and modify visual tests
wch authored
102 geom_dotplot(binwidth=.2, binaxis="y", stackdir="center")
103 save_vtest("bin y, continous x-axis, grouping by x")
b3b8fc6 @wch dotplot: add tests
wch authored
104
105 ggplot(dat2, aes(x=as.numeric(x), y=y)) +
d3ee17b @wch Move and modify visual tests
wch authored
106 geom_dotplot(binwidth=.2, binaxis="y", stackdir="center")
107 save_vtest("bin y, continous x-axis, single x group")
108
04307a8 @wch dotplot: implement stacking
wch authored
109
110 # Stacking groups
111 ggplot(dat2, aes(x=y, fill=x)) +
112 geom_dotplot(binwidth=.25, stackgroups=TRUE, binpositions="all", alpha=0.5)
113 save_vtest("stackgroups with 3 groups, dot-density with aligned bins")
114
115 ggplot(dat2, aes(x=y, fill=x)) +
116 geom_dotplot(binwidth=.25, stackgroups=TRUE, method="histodot", alpha=0.5)
117 save_vtest("stackgroups with 3 groups, histodot")
118
119 ggplot(dat2, aes(x=1, y=y, fill=x)) +
120 geom_dotplot(binaxis="y", binwidth=.25, stackgroups=TRUE, method="histodot", alpha=0.5)
121 save_vtest("stackgroups with 3 groups, bin y, histodot")
122
123 # This one is currently broken but it would be a really rare case, and it
124 # probably requires a really ugly hack to fix
125 ggplot(dat2, aes(x=x, y=y, fill=g)) +
126 geom_dotplot(binaxis="y", binwidth=.25, stackgroups=TRUE, method="histodot",
127 alpha=0.5, stackdir="centerwhole")
128 save_vtest("bin y, dodging, stackgroups with 3 groups, histodot (currently broken)")
129
130 ggplot(dat2, aes(x=y, fill=g)) +
131 geom_dotplot(binwidth=.25, stackgroups=TRUE, method="histodot", alpha=0.5) +
132 facet_grid(x ~ .)
133 save_vtest("facets, 3 groups, histodot, stackgroups")
134
135 end_vcontext()
Something went wrong with that request. Please try again.