How to get the ggplot double bar graph as a GIF file with the following specifications - DPI of 300 and Width of 440 pixels.
I use the following code and data for making the graph
graph_text <- structure(list(
percentage = c(57.14, 29.76, 69.32, 28.41, 57.89, 34.21, 58.59, 33.33, 48.42, 42.11, 59.77, 29.89, 72.13, 18.03, 53.33, 33.33, 55.1, 40.82, 46.55, 37.93),
year = c(2020L, 2020L, 2019L, 2019L, 2018L, 2018L, 2017L, 2017L, 2016L, 2016L, 2015L, 2015L, 2014L, 2014L, 2013L, 2013L, 2012L, 2012L, 2011L, 2011L),
gender = c("male", "female", "male", "female", "male", "female", "male", "female", "male", "female", "male", "female", "male", "female", "male", "female", "male", "female", "male", "female")
),
class = "data.frame", row.names = c(NA, -20L)
)
ymax <- max(graph_text$percentage)
ggplot(aes(x = year, y = percentage, color = gender, fill = gender), data = graph_text) +
geom_bar(position = "dodge", stat = "identity") +
theme_classic() +
geom_text(aes(label = percentage), size = 4, position = position_dodge(width = 1.1), vjust = -0.2) +
scale_y_continuous(limits = c(0, 1.4 * ymax))
Session info -
R version 4.1.0 (2021-05-18)Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)
Matrix products: default
locale:[1] LC_COLLATE=English_India.1252 LC_CTYPE=English_India.1252 LC_MONETARY=English_India.1252[4] LC_NUMERIC=C LC_TIME=English_India.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] fansi_0.5.0 assertthat_0.2.1 dplyr_1.0.6 crayon_1.4.1 utf8_1.2.1
[6] grid_4.1.0 R6_2.5.0 DBI_1.1.1 lifecycle_1.0.0 gtable_0.3.0
[11] magrittr_2.0.1 scales_1.1.1 ggplot2_3.3.3 pillar_1.6.1 rlang_0.4.11
[16] generics_0.1.0 vctrs_0.3.8 ellipsis_0.3.2 tools_4.1.0 glue_1.4.2
[21] purrr_0.3.4 munsell_0.5.0 compiler_4.1.0 pkgconfig_2.0.3 colorspace_2.0-1
[26] tidyselect_1.1.1 tibble_3.1.2