Reproduce a 'The Economist' chart with dual axis

前端 未结 4 1753
借酒劲吻你
借酒劲吻你 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:16

    Your code for combining the plots isn't working in my R session, so I can't help you there. But here are the two questions you asked for:

    . use ggtitle
    2. use scale_x_continuous
    3. Note: I've also changed your ylim to lims and your labs to theme(..., axis.title= element_blank(), ...)

    p1 <- ggplot(rus, aes(X, Russia)) + geom_line(colour = "#68382C", size = 1.5) + ggtitle("Number in Russia") +
      lims(y= c(0, 200)) + 
      scale_x_continuous(breaks= c(1996, seq(2000,2015,5))) +
      theme(#plot.margin = unit(c(2,1,0,0), "cm"),
        panel.grid.minor = element_blank(), 
        panel.grid.major = element_line(color = "gray50", size = 0.5),
        panel.grid.major.x = element_blank(),
        text=element_text(family="ITCOfficinaSans LT Book"),
        axis.text.y = element_text(colour="#68382C", size = 14),
        axis.text.x = element_text(size = 14),
        axis.title= element_blank(),
        axis.ticks = element_line(colour = 'gray50'),
        plot.title = element_text(hjust=0,vjust=2.12, colour="#68382C", size = 14, family = "ITCOfficinaSans LT Bold")) 
    
    p2 <- ggplot(world, aes(X, World)) + geom_line(colour = "#00a4e6", size = 1.5) + ggtitle("Rest of World") +
      lims(y= c(0, 2000)) +  scale_x_continuous(breaks= c(1996, seq(2000,2015,5))) +
      theme(#plot.margin = unit(c(2,1,0,0), "cm"),
        panel.grid.minor = element_blank(), 
        panel.grid.major = element_blank(),
        text = element_text(family="ITCOfficinaSans LT Book"),
        axis.text.y = element_text(colour="#00a4e6", size=14),
        axis.text.x = element_text(size=14),
        axis.title= element_blank(),
        axis.ticks = element_blank(),
        plot.title = element_text(hjust = 1, vjust=2.12, colour="#00a4e6", size = 14, family = "ITCOfficinaSans LT Bold"))
    

提交回复
热议问题