I came up with a weekly R challenge, as a way to “force” myself into learning new things. One figure, every week! The catch is that every time I should be trying something new… maybe I’ll use a new type of visualization for first time, or maybe I’ll explore a new dataset. Initially I thought it would be neat if there was some unifying topic, e.g. water, but then I decided to keep it open.

This is my first entry for 2019! I decided to keep it simple and relevant to what is going on in my life right now. I just moved out of Singapore and currently I am visiting my family in Bulgaria. I realized I know less about Bulgarian water consumption than for Singaporean one, so I decided to explore some of the national statistics.

This one is really straightforward as a visualization. Here are few details:

  1. I used data on domestic water consumption (liter/capita/day) for Singapore and Bulgaria for the period 2007-2017.
    • The Bulgarian data comes from our National Statistics Institute (nsi.bg);
    • the Singaporean data comes from Straits Times article (Mar 7, 2018), where the original source is provided as data.gov.sg. Probably because I am not in Singapore, I cannot find the data there, even though I’ve actually seen it before (while I lived in SG).
  2. I wanted to compare the trends, so I looked at different types of visualizations, but at the end decided to go for the simplest one I could think of, the bar plot.
  3. I used R Base graphics, because it seemed to be overkill to use ggplot2 for such a simple graph. Of course, I spent some time to adjust the default parameters.
  4. Since this is a water-related graph, I thought that the color palette should be blue. While I was browsing, I found:
    • Pantone Color of the Year 2019 is PANTONE 16-1546 Living Coral (HEX #FF6D70). It’s a very pretty coral color, but unfortunately didn’t fit with my idea. I also browsed through the five different color palettes featuring the Living Coral color (click) and Under the Sea seemed promising. Eventually, I gave up on this, because I found…
    • dichromat library! I was reading “Using colors in R” where I found about this library. I usually use CollorBrewer, but I am getting bored with it, so I thought it is a great opportunity to try out the dichromat. This library contains 17 color schemes, which are “suitable for people with deficient or anomalous red-green vision”. I chose the LightBluetoDarkBlue.10, but before I move on to the graph code, I will plot the palettes…

  1. Graph and code
year <- c(2010:2017)
Sofia <- c(90, 94, 102, 101, 89, 96, 94, 97)  # l/capita/day
Sofia.cap <- c(140, 136, 134, 130, 128, 127, 127, 126)  # l/cap/day
BG <- c(97, 100, 102, 99, 96, 99, 100, 99)  # l/cap/day
Singapore <- c(154, 153, 152, 151, 150, 151, 148, 143)  #l/cap/day
data <- data.frame(year, BG, SG=Singapore)

Domestic water use in Singapore has been dropping in the period of interest, but is still quite high in comparison with Bulgarian domestic water use. The mean for the period (2010-2017) for Bulgaria is 99 l/cap/day, while for Singapore is 150.25 l/cap/day. It is probably unfair comparison, because Singapore is in a tropical climate.

# setting the graph params for background, colors, fonts etc.
par(mar=c(4, 4, 2, 0),bg="#1A66FF", col.axis="#E6FFFF", col.lab="#E6FFFF", family="mono", fg="#E6FFFF")
# color
cols <- rev(dichromat_pal("LightBluetoDarkBlue.10")(8))
# barplot
barplot(as.matrix(data[,-1]), names.arg = c("Bulgaria", "Singapore"), beside = TRUE, xpd=FALSE, ylim=c(80, 160), border = NA, legend.text = data[,1], args.legend = list(x="topleft", bty="n", border="#1A66FF", text.col="#E6FFFF"), las=1, col=cols, ylab="l/cap/day")
abline(h=c(mean(data$BG), mean(data$SG)), col="#1A66FF", lty=3)  # mean of BG & SG
mtext("@DenitzaV", side=1, line=3, adj = 1, col="#E6FFFF", cex=0.8)

And that’s it for this week! I still have few more Bulgarian datasets to explore, so probably next week figure will be on a similar topic.

LS0tDQp0aXRsZTogIkRvbWVzdGljIHdhdGVyIHVzZSBpbiBTRyAmIEJHIg0KYXV0aG9yOiAiRGVuaXR6YSBELiBWb3V0Y2hrb3ZhIg0KZGF0ZTogIjExIEphbiAyMDE5ICgjMikiDQpvdXRwdXQ6IA0KICBodG1sX25vdGVib29rOiANCiAgICBoaWdobGlnaHQ6IGthdGUNCi0tLQ0KDQpfSSBjYW1lIHVwIHdpdGggYSB3ZWVrbHkgX19SX18gY2hhbGxlbmdlLCBhcyBhIHdheSB0byAiZm9yY2UiIG15c2VsZiBpbnRvIGxlYXJuaW5nIG5ldyB0aGluZ3MuIE9uZSBmaWd1cmUsIGV2ZXJ5IHdlZWshIFRoZSBjYXRjaCBpcyB0aGF0IGV2ZXJ5IHRpbWUgSSBzaG91bGQgYmUgdHJ5aW5nIHNvbWV0aGluZyBuZXcuLi4gbWF5YmUgSSdsbCB1c2UgIGE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