1
1
# ' @eval get_description('annotation_pie_chart')
2
2
# ' @include annotation_source_class.R
3
3
# ' @export
4
- annotation_bar_chart <- function (factor_name ,
5
- label_rotation = FALSE ,
6
- label_location = " inside" ,
7
- label_type = " percent" ,
8
- legend = FALSE ,
9
- ... ) {
4
+ annotation_bar_chart <- function (
5
+ factor_name ,
6
+ label_rotation = FALSE ,
7
+ label_location = " inside" ,
8
+ label_type = " percent" ,
9
+ legend = FALSE ,
10
+ ... ) {
10
11
out <- struct :: new_struct(
11
12
" annotation_bar_chart" ,
12
13
factor_name = factor_name ,
@@ -16,7 +17,7 @@ annotation_bar_chart <- function(factor_name,
16
17
legend = legend ,
17
18
...
18
19
)
19
-
20
+
20
21
return (out )
21
22
}
22
23
@@ -111,7 +112,7 @@ setMethod(
111
112
group_by(.data [[obj $ factor_name ]]) %> %
112
113
summarise(count = n()) %> %
113
114
tidyr :: complete(.data [[obj $ factor_name ]], fill = list (count = 0 ))
114
-
115
+
115
116
# labels
116
117
df $ label <- " "
117
118
if (obj $ label_type == " percent" ) {
@@ -121,7 +122,7 @@ setMethod(
121
122
} else if (obj $ label_type == " count" ) {
122
123
df $ label <- as.character(df $ count )
123
124
}
124
-
125
+
125
126
if (obj $ label_rotation ) {
126
127
df $ label <- paste0(" " , df $ label , " " )
127
128
} else {
@@ -131,7 +132,7 @@ setMethod(
131
132
df $ label <- paste0(df $ label )
132
133
}
133
134
}
134
-
135
+
135
136
# add newlines of spaces to offset depending on rotation
136
137
if (! obj $ legend ) {
137
138
if (obj $ label_type != " none" ) {
@@ -143,13 +144,13 @@ setMethod(
143
144
df $ label <- df [[obj $ factor_name ]]
144
145
}
145
146
}
146
-
147
+
147
148
if (! obj $ label_rotation ) {
148
149
df $ rotate <- 0
149
150
} else {
150
151
df $ rotate <- - 90
151
152
}
152
-
153
+
153
154
df $ hjust <- 0.5
154
155
if (obj $ label_rotation ) {
155
156
if (obj $ label_location == " inside" ) {
@@ -158,7 +159,7 @@ setMethod(
158
159
df $ hjust <- 1
159
160
}
160
161
}
161
-
162
+
162
163
# plot
163
164
g <- ggplot(
164
165
data = df ,
@@ -182,15 +183,15 @@ setMethod(
182
183
structToolbox ::: theme_Publication(12 ) +
183
184
scale_fill_Publication() +
184
185
theme_Publication()
185
-
186
+
186
187
# legend
187
188
if (! obj $ legend ) {
188
189
g <- g + theme(legend.position = " none" )
189
190
} else {
190
191
g <- g + theme(axis.text.x = element_blank())
191
192
}
192
-
193
-
193
+
194
+
194
195
return (g )
195
196
}
196
197
)
0 commit comments