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.