Last active
December 24, 2015 22:49
-
-
Save thomaskern/6875977 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cutie = cut(df$volume,c(0,216,433,650,867,29000)) | |
ggplot(df,aes(type,change,fill=cutie)) + geom_hline(yintercept=0,color="white",size=1)+ geom_bar(stat="identity") + coord_flip() + theme(panel.grid.major.y=element_blank(),legend.position=c(.9,0.3),legend.background=element_rect(fill="transparent")) + labs(x="",y="Change [%]",title="Change in New Brunswick Fruit Production - 2006 vs 2011") + scale_y_continuous(breaks=seq(-25,100,25)) + theme(plot.margin = unit(c(0.3, 0.3, -0.03, -0.15), "lines")) + scale_fill_manual("Volume [ac]",values=c("#B2CDDF","#5E9CCB","#2F6BAC","#173987","black"),breaks=c("(0,216]","(216,433]","(433,650]","(650,867]","(867,2.9e+04]"),labels=c("< 220","221-430","431-650","651-900","29k")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
volume | type | change | berry | |
---|---|---|---|---|
550 | Apples | -31 | F | |
6 | Pears | -14 | F | |
3 | Plums and prunes | -25 | F | |
0 | Cherries (sweet) | 0 | F | |
2 | Cherries (sour) | 100 | F | |
70 | Grapes | 27 | F | |
327 | Strawberries | -30 | T | |
116 | Raspberries | -29 | T | |
866 | Cranberries | 59 | T | |
27878 | Blueberries | 26 | T | |
28 | Other fruits | 0 | F |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
library(grid) | |
df = read.csv("fruit_production.csv") | |
df$type = factor(df$type,levels=df$type[order(df$change)]) | |
p = ggplot(df,aes(type,change,fill=change>0)) + geom_bar(stat="identity") + coord_flip() | |
p = p + theme(panel.grid.major.y=element_blank(),legend.position="None") | |
p = p + labs(x="",title="New Brunswick Fruit Production",y="Change between 2006 and 2011 [%]") | |
p = p + scale_y_continuous(breaks=seq(-25,100,25)) | |
p = p + theme(plot.margin = unit(c(0.0, 0.3, -0.03, -0.85), "lines")) + theme(axis.title.x = element_text(size=10)) | |
ggsave("fruits.pdf",p) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> df$type = factor(df$type,levels=df$type[order(df$change)]) | |
> ggplot(df,aes(type,change,fill=cut)) + geom_bar(stat="identity") + coord_flip() + theme(panel.grid.major.y=element_blank(),legend.position="None") + labs(x="",y="Change [%]",title="Change in New Brunswick Fruit Production - 2006 vs 2011") + scale_y_continuous(breaks=seq(-25,100,25)) + theme(plot.margin = unit(c(0.3, 0.3, -0.03, -0.15), "lines")) + scale_fill_brewer() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ggplot(df,aes(type,change,fill=cut(df$volume,c(0,216,433,650,867,29000)))) + theme_bw() + geom_hline(yintercept=0,color="grey",size=1)+ geom_bar(stat="identity") + coord_flip() + theme(panel.grid.major.y=element_blank(),legend.position=c(.9,0.3),legend.background=element_rect(fill="transparent")) + labs(x="",y="Change [%]",title="Change in New Brunswick Fruit Production - 2006 vs 2011") + scale_y_continuous(breaks=seq(-25,100,25)) + theme(plot.margin = unit(c(0.3, 0.3, -0.03, -0.15), "lines")) + scale_fill_manual("Volume [ac]",values=c("#B2CDDF","#5E9CCB","#2F6BAC","#173987","black"),breaks=c("(0,216]","(216,433]","(433,650]","(650,867]","(867,2.9e+04]"),labels=c("< 220","221-430","431-650","651-900","29k")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment