Skip to content

Instantly share code, notes, and snippets.

@ramnathv
Created October 15, 2010 17:38
Show Gist options
  • Save ramnathv/628605 to your computer and use it in GitHub Desktop.
Save ramnathv/628605 to your computer and use it in GitHub Desktop.
country loccurover text
Switzerland 80 6.78
Brazil 40 5.26
Euro area 30 4.79
Canada 10 4.18
Japan 5 3.91
United States 0 3.71
Britain -5 3.63
Singapore -10 3.46
South Korea -20 3.03
South Africa -25 2.79
Mexico -30 2.58
Thailand -35 2.44
Russia -38 2.39
Malaysia -39 2.25
China -40 2.18
library(ggplot2);
bunfight = read.csv('bunfight.csv');
base_size = 12;
economist = theme_update(plot.background = theme_rect(fill = 'lightblue',
colour = 'black'), panel.background = theme_rect(fill = 'lightblue', colour =
NA), axis.text.x = theme_text(colour = 'black', size = base_size * 0.8,
lineheight = 0.9, vjust = 1), axis.text.y = theme_text(colour = 'black', size
= base_size * 0.8, lineheight = 0.9, hjust = 1), panel.border = theme_blank()
)
base = ggplot(bunfight, aes(x = reorder(country, loccurover), y = loccurover)) +
geom_bar(stat = 'identity', fill = 'blue') +
coord_flip() +
xlab(NULL) + ylab(NULL) + opts(axis.ticks = theme_blank()) +
geom_hline(yintercept = seq(-40, 80, by = 20), colour = 'white',
size = 0.25) +
geom_text(aes(label = text), y = 85, size = 3, colour = 'black') +
economist
makeFootnote('Sources: McDonalds, The Economist');
makeTitle('Bunfight');
## code adapted from Mark Heckmann: http://goo.gl/llx3
makeFootnote <- function(footnoteText =
format(Sys.time(), "%d %b %Y"),
size= .7, color= grey(.2))
{
require(grid)
pushViewport(viewport())
grid.text(label= footnoteText ,
x = unit(0,"npc") + unit(7, "mm"),
y= unit(2, "mm"),
just=c("left", "bottom"),
gp=gpar(cex= size, col=color))
popViewport()
}
makeTitle <- function(titleText = 'Title',
size = 1, color = 'black')
{
require(grid)
pushViewport(viewport())
grid.text(label = titleText ,
x = unit(0,"npc") + unit(7, "mm"),
y = unit(0.99, "npc"),
just=c("left", "top"),
gp=gpar(cex= size, col=color, fontface = 'bold'))
popViewport()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment