Skip to content

Commit 4b9f74f

Browse files
committed
Update 2021-08-04-bar-charts.Rmd
fix
1 parent 2a76987 commit 4b9f74f

File tree

1 file changed

+5
-35
lines changed

1 file changed

+5
-35
lines changed

ggplot2/2021-08-04-bar-charts.Rmd

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -160,29 +160,7 @@ p <- ggplot(df.summ, aes(x = cut, y = Mean, ymin = Min, ymax = Max, fill = cut))
160160
geom_errorbar() +
161161
ggtitle("Bar chart with Error Bars")
162162
163-
fig <- ggplotly(p)
164-
165-
fig
166-
```
167-
168-
# Stacked Bar Chart
169-
<code>geom_bar</code> with stacked traces
170-
171-
```{r}
172-
library(plotly)
173-
library(dplyr)
174-
library(reshape)
175-
176-
df <- structure(c(106487, 495681, 1597442, 2452577, 2065141, 2271925, 4735484, 3555352, 8056040, 4321887, 2463194, 347566, 621147, 1325727, 1123492, 800368, 761550, 1359737, 1073726, 36, 53, 141, 41538, 64759, 124160, 69942, 74862, 323543, 247236, 112059, 16595, 37028, 153249, 427642, 1588178, 2738157, 2795672, 2265696, 11951, 33424, 62469, 74720, 166607, 404044, 426967, 38972, 361888, 1143671, 1516716, 160037, 354804, 996944, 1716374, 1982735, 3615225, 4486806, 3037122, 17, 54, 55, 210, 312, 358, 857, 350, 7368, 8443, 6286, 1750, 7367, 14092, 28954, 80779, 176893, 354939, 446792, 33333, 69911, 53144, 29169, 18005, 11704, 13363, 18028, 46547, 14574, 8954, 2483, 14693, 25467, 25215, 41254, 46237, 98263, 185986), .Dim = c(19, 5), .Dimnames = list(c("1820-30", "1831-40", "1841-50", "1851-60", "1861-70", "1871-80", "1881-90", "1891-00", "1901-10", "1911-20", "1921-30", "1931-40", "1941-50", "1951-60", "1961-70", "1971-80", "1981-90", "1991-00", "2001-06"), c("Europe", "Asia", "Americas", "Africa", "Oceania")))
177-
df.m <- melt(df)
178-
df.m <- rename(df.m, Period = Var1, Region = Var2)
179-
180-
p <- ggplot(df.m, aes(x = Period, y = value/1e+06,fill = Region)) + ggtitle("Migration to the United States by Source Region (1820-2006), In Millions")
181-
p <- p + geom_bar(stat = "identity", position = "stack")
182-
183-
fig <- ggplotly(p)
184-
185-
fig
163+
ggplotly(p)
186164
```
187165

188166
# Ordered Bar Chart
@@ -198,9 +176,7 @@ dane$x<-as.factor(dane$x)
198176
p <- ggplot(data=dane,aes(x=x,y=y,fill=g)) +
199177
geom_bar(stat="identity")
200178
201-
fig <- ggplotly(p)
202-
203-
fig
179+
ggplotly(p)
204180
```
205181

206182
# Precentages
@@ -218,9 +194,7 @@ p <- ggplot(df, aes(x = color)) +
218194
ylab("Percent") +
219195
ggtitle("Show precentages in bar chart")
220196
221-
fig <- ggplotly(p)
222-
223-
fig
197+
ggplotly(p)
224198
```
225199

226200
Set manual colors using <code>geom_bar</code> to manually specify colors.
@@ -238,9 +212,7 @@ p <- ggplot(df, aes(x = color)) +
238212
ylab("Count") +
239213
ggtitle("Specify manual colors in a bar chart")
240214
241-
fig <- ggplotly(p)
242-
243-
fig
215+
ggplotly(p)
244216
```
245217

246218
# Reordered Bar Chart
@@ -260,7 +232,5 @@ p <- ggplot(df, aes(x, y, fill = x)) +
260232
geom_bar(stat = "identity") +
261233
ggtitle("Bar Chart with changed factor levels")
262234
263-
fig <- ggplotly(p)
264-
265-
fig
235+
ggplotly(p)
266236
```

0 commit comments

Comments
 (0)