Mercurial > hg > plosone_underreview
comparison scripts_R/MetadataPlots.R @ 91:d3e05cd49feb branch-tests
trying to plot wrt PLOSONE guidelines
author | Maria Panteli <m.x.panteli@gmail.com> |
---|---|
date | Mon, 02 Oct 2017 15:32:51 +0100 |
parents | bde45ce0eeab |
children |
comparison
equal
deleted
inserted
replaced
89:8a2d56880050 | 91:d3e05cd49feb |
---|---|
1 library(rworldmap) | 1 library(rworldmap) |
2 library(ggplot2) | 2 library(ggplot2) |
3 | |
4 library(extrafont) | |
5 font_import() | |
6 loadfonts() | |
7 Arial <- Type1Font(family="Arial", metrics=c("ArialMT.afm","arial-BoldMT.afm","Arial-ItalicMT.afm", "Arial-BoldItalicMT.afm")) | |
8 postscriptFonts(Arial=Arial) | |
9 par(family="Arial") | |
3 | 10 |
4 PlotBarChart<- function(df, cat="Language", ordercat="REGION", mincount=10, legend=T, color_plt="Paired"){ | 11 PlotBarChart<- function(df, cat="Language", ordercat="REGION", mincount=10, legend=T, color_plt="Paired"){ |
5 idx_cat = which(colnames(df)==cat) | 12 idx_cat = which(colnames(df)==cat) |
6 idx_ordercat = which(colnames(df)==ordercat) | 13 idx_ordercat = which(colnames(df)==ordercat) |
7 dfsub <- subset(df, df[,idx_cat]!="") | 14 dfsub <- subset(df, df[,idx_cat]!="") |
11 dfsub[,idx_cat] <- factor(dfsub[,idx_cat], levels=unique(dfsub[,idx_cat])) | 18 dfsub[,idx_cat] <- factor(dfsub[,idx_cat], levels=unique(dfsub[,idx_cat])) |
12 g = ggplot(dfsub,aes(dfsub[,idx_cat], fill=dfsub[,idx_ordercat], order=-as.numeric(dfsub[,idx_ordercat])))+geom_bar() | 19 g = ggplot(dfsub,aes(dfsub[,idx_cat], fill=dfsub[,idx_ordercat], order=-as.numeric(dfsub[,idx_ordercat])))+geom_bar() |
13 #g = g+ylim("0", "100")#+scale_y_discrete(breaks=c("100"),labels=c("100+")) | 20 #g = g+ylim("0", "100")#+scale_y_discrete(breaks=c("100"),labels=c("100+")) |
14 g=g+scale_y_continuous(limits=c(0, 200), breaks=seq(0,200,40)) | 21 g=g+scale_y_continuous(limits=c(0, 200), breaks=seq(0,200,40)) |
15 g=g+scale_fill_brewer(palette=color_plt) | 22 g=g+scale_fill_brewer(palette=color_plt) |
16 g=g+theme(axis.text.x=element_text(angle=90,hjust=1,vjust=0.5)) | 23 g=g+theme(axis.text.x=element_text(angle=90,hjust=1,vjust=0.5), text = element_text(size=12)) |
17 g=g+labs(y="Counts",x=cat)+coord_flip()+theme_bw() | 24 g=g+labs(y="Counts",x=cat)+coord_flip()+theme_bw() |
18 if (legend){ | 25 if (legend){ |
19 g=g+guides(fill = guide_legend(title = ordercat))} | 26 g=g+guides(fill = guide_legend(title = ordercat))} |
20 else{ | 27 else{ |
21 g=g+guides(fill="none") | 28 g=g+guides(fill="none") |
74 # avoid antarctica | 81 # avoid antarctica |
75 #mapParams <- mapCountryData(spdf, nameColumnToPlot="Outliers", ylim=c(-60,90), catMethod=seq(0,1,0.1), missingCountryCol='grey',colourPalette='heat', mapTitle="", addLegend=FALSE) | 82 #mapParams <- mapCountryData(spdf, nameColumnToPlot="Outliers", ylim=c(-60,90), catMethod=seq(0,1,0.1), missingCountryCol='grey',colourPalette='heat', mapTitle="", addLegend=FALSE) |
76 #do.call( addMapLegend, c(mapParams, labelFontSize=0.7, legendWidth=0.5, tcl=0.3, legendMar = 7, legendLabels="all",horizontal=T, legendIntervals="page")) | 83 #do.call( addMapLegend, c(mapParams, labelFontSize=0.7, legendWidth=0.5, tcl=0.3, legendMar = 7, legendLabels="all",horizontal=T, legendIntervals="page")) |
77 legend("left", legend = c(paste(seq(90,0,-10),'-',seq(100,10,-10),'%'), 'NA'), fill = c(heat.colors(10, alpha = 1), 'grey'), cex = 0.56, bty = "o",bg="white",box.lwd=0,box.col="white") | 84 legend("left", legend = c(paste(seq(90,0,-10),'-',seq(100,10,-10),'%'), 'NA'), fill = c(heat.colors(10, alpha = 1), 'grey'), cex = 0.56, bty = "o",bg="white",box.lwd=0,box.col="white") |
78 if (output!=''){ | 85 if (output!=''){ |
79 pdf(output) | 86 if (grepl('.pdf', output)){ |
87 pdf(output, pointsize=12) | |
88 } else if (grepl('.eps', output)){ | |
89 postscript(output, pointsize=12) | |
90 } | |
80 #mapParams <- mapCountryData(spdf, nameColumnToPlot="Outliers",catMethod=seq(0,70,5),missingCountryCol='grey',colourPalette='heat', mapTitle="", addLegend=FALSE) | 91 #mapParams <- mapCountryData(spdf, nameColumnToPlot="Outliers",catMethod=seq(0,70,5),missingCountryCol='grey',colourPalette='heat', mapTitle="", addLegend=FALSE) |
81 mapParams <- mapCountryData(spdf, nameColumnToPlot="Outliers", catMethod=seq(0,1,0.1), missingCountryCol='grey',colourPalette='heat', mapTitle="", addLegend=FALSE) | 92 mapParams <- mapCountryData(spdf, nameColumnToPlot="Outliers", catMethod=seq(0,1,0.1), missingCountryCol='grey',colourPalette='heat', mapTitle="", addLegend=FALSE) |
82 #mapParams <- mapCountryData(spdf, nameColumnToPlot="Outliers", ylim=c(-60,90), catMethod=seq(0,1,0.1), missingCountryCol='grey',colourPalette='heat', mapTitle="", addLegend=FALSE) | 93 #mapParams <- mapCountryData(spdf, nameColumnToPlot="Outliers", ylim=c(-60,90), catMethod=seq(0,1,0.1), missingCountryCol='grey',colourPalette='heat', mapTitle="", addLegend=FALSE) |
83 #do.call( addMapLegend, c(mapParams, labelFontSize=0.7, legendWidth=0.5, tcl=0.3, legendMar=7, legendLabels="all",horizontal=T, legendIntervals="page")) | 94 #do.call( addMapLegend, c(mapParams, labelFontSize=0.7, legendWidth=0.5, tcl=0.3, legendMar=7, legendLabels="all",horizontal=T, legendIntervals="page")) |
84 legend("left", legend = c(paste(seq(90,0,-10),'-',seq(100,10,-10),'%'), 'NA'), fill = c(heat.colors(10, alpha = 1), 'grey'), cex = 0.56, bty = "o",bg="white",box.lwd=0,box.col="white") | 95 legend("left", legend = c(paste(seq(90,0,-10),'-',seq(100,10,-10),'%'), 'NA'), fill = c(heat.colors(10, alpha = 1), 'grey'), cex = 0.56, bty = "o",bg="white",box.lwd=0,box.col="white") |