Reproduce a 'The Economist' chart with dual axis

前端 未结 4 1755
借酒劲吻你
借酒劲吻你 2020-12-16 05:49

I was trying to replicate this chart from The Economist (the one on the left). The chart plots the number of billionaires in Russia on the left y-axis and the numb

4条回答
  •  星月不相逢
    2020-12-16 06:19

    Here's a solution using R base graphics, rather than ggplot. I didn't change the font family, as that's only portable across systems with the same fonts installed (I don't have Officiana here). It's easy to add a family argument to mtext to do so.

    par(mar = c(3, 3, 3, 3), las = 1)
    plot(tmp[,c(1,3)], type = 'n', axes = FALSE, ylim = c(0, 2000))
    abline(h = c(0, 500, 1000, 1500, 2000), col = "grey")
    points(tmp[,c(1,3)], type = 'l', col = "blue", lwd = 2)
    points(x = tmp[,1], y = tmp[,2] * 10, type = 'l', col = "brown", lwd = 2)
    axis(side = 4, at = c(0, 500, 1000, 1500, 2000), tick = FALSE,
         col.axis = "blue", line = 1, hadj = 1)
    axis(side = 2, at = c(0, 500, 1000, 1500, 2000), tick = FALSE,
         col.axis = "brown", hadj = 1,
         labels = c(0, 50, 100, 150, 200))
    axis(side = 1, at = c(1996, 2000, 2005, 2010, 2015), lwd = 0, line = -1,
         lwd.ticks = 2, col.ticks = "grey")
    mtext("Number in Russia", side = 2, col = "brown", at = 2150, line = 2.5,
          adj = 0)
    mtext("Rest of World", side = 4, col = "blue", at = 2150, line = 2,
          adj = 1)
    

提交回复
热议问题