Mercurial > hg > plosone_underreview
changeset 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 | 8a2d56880050 |
children | ce525367960e |
files | notebooks/explain_components.ipynb scripts_R/MetadataPlots.R scripts_R/Metadata_subsetBLSM.R scripts_R/PlotOutliersCountry.R |
diffstat | 4 files changed, 68 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/notebooks/explain_components.ipynb Mon Oct 02 12:37:55 2017 +0100 +++ b/notebooks/explain_components.ipynb Mon Oct 02 15:32:51 2017 +0100 @@ -32,7 +32,9 @@ { "cell_type": "code", "execution_count": 2, - "metadata": {}, + "metadata": { + "collapsed": false + }, "outputs": [ { "name": "stdout", @@ -63,6 +65,7 @@ "cell_type": "code", "execution_count": 14, "metadata": { + "collapsed": false, "scrolled": false }, "outputs": [ @@ -229,7 +232,9 @@ { "cell_type": "code", "execution_count": 3, - "metadata": {}, + "metadata": { + "collapsed": false + }, "outputs": [ { "name": "stdout", @@ -267,7 +272,9 @@ { "cell_type": "code", "execution_count": 62, - "metadata": {}, + "metadata": { + "collapsed": false + }, "outputs": [ { "name": "stdout", @@ -299,7 +306,9 @@ { "cell_type": "code", "execution_count": 13, - "metadata": {}, + "metadata": { + "collapsed": false + }, "outputs": [ { "data": { @@ -362,7 +371,9 @@ { "cell_type": "code", "execution_count": 4, - "metadata": {}, + "metadata": { + "collapsed": false + }, "outputs": [ { "name": "stdout", @@ -405,7 +416,9 @@ { "cell_type": "code", "execution_count": 6, - "metadata": {}, + "metadata": { + "collapsed": false + }, "outputs": [ { "name": "stdout", @@ -423,7 +436,9 @@ { "cell_type": "code", "execution_count": 65, - "metadata": {}, + "metadata": { + "collapsed": false + }, "outputs": [ { "name": "stdout", @@ -493,7 +508,9 @@ { "cell_type": "code", "execution_count": 69, - "metadata": {}, + "metadata": { + "collapsed": false + }, "outputs": [ { "data": { @@ -528,7 +545,9 @@ { "cell_type": "code", "execution_count": 67, - "metadata": {}, + "metadata": { + "collapsed": false + }, "outputs": [ { "name": "stdout", @@ -568,7 +587,9 @@ { "cell_type": "code", "execution_count": 51, - "metadata": {}, + "metadata": { + "collapsed": false + }, "outputs": [ { "data": { @@ -627,7 +648,9 @@ { "cell_type": "code", "execution_count": 26, - "metadata": {}, + "metadata": { + "collapsed": false + }, "outputs": [ { "data": { @@ -659,7 +682,9 @@ { "cell_type": "code", "execution_count": 31, - "metadata": {}, + "metadata": { + "collapsed": false + }, "outputs": [ { "data": { @@ -692,7 +717,9 @@ { "cell_type": "code", "execution_count": 33, - "metadata": {}, + "metadata": { + "collapsed": false + }, "outputs": [ { "data": {
--- a/scripts_R/MetadataPlots.R Mon Oct 02 12:37:55 2017 +0100 +++ b/scripts_R/MetadataPlots.R Mon Oct 02 15:32:51 2017 +0100 @@ -1,6 +1,13 @@ library(rworldmap) library(ggplot2) +library(extrafont) +font_import() +loadfonts() +Arial <- Type1Font(family="Arial", metrics=c("ArialMT.afm","arial-BoldMT.afm","Arial-ItalicMT.afm", "Arial-BoldItalicMT.afm")) +postscriptFonts(Arial=Arial) +par(family="Arial") + PlotBarChart<- function(df, cat="Language", ordercat="REGION", mincount=10, legend=T, color_plt="Paired"){ idx_cat = which(colnames(df)==cat) idx_ordercat = which(colnames(df)==ordercat) @@ -13,7 +20,7 @@ #g = g+ylim("0", "100")#+scale_y_discrete(breaks=c("100"),labels=c("100+")) g=g+scale_y_continuous(limits=c(0, 200), breaks=seq(0,200,40)) g=g+scale_fill_brewer(palette=color_plt) - g=g+theme(axis.text.x=element_text(angle=90,hjust=1,vjust=0.5)) + g=g+theme(axis.text.x=element_text(angle=90,hjust=1,vjust=0.5), text = element_text(size=12)) g=g+labs(y="Counts",x=cat)+coord_flip()+theme_bw() if (legend){ g=g+guides(fill = guide_legend(title = ordercat))} @@ -76,7 +83,11 @@ #do.call( addMapLegend, c(mapParams, labelFontSize=0.7, legendWidth=0.5, tcl=0.3, legendMar = 7, legendLabels="all",horizontal=T, legendIntervals="page")) 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") if (output!=''){ - pdf(output) + if (grepl('.pdf', output)){ + pdf(output, pointsize=12) + } else if (grepl('.eps', output)){ + postscript(output, pointsize=12) + } #mapParams <- mapCountryData(spdf, nameColumnToPlot="Outliers",catMethod=seq(0,70,5),missingCountryCol='grey',colourPalette='heat', mapTitle="", addLegend=FALSE) mapParams <- mapCountryData(spdf, nameColumnToPlot="Outliers", catMethod=seq(0,1,0.1), missingCountryCol='grey',colourPalette='heat', mapTitle="", addLegend=FALSE) #mapParams <- mapCountryData(spdf, nameColumnToPlot="Outliers", ylim=c(-60,90), catMethod=seq(0,1,0.1), missingCountryCol='grey',colourPalette='heat', mapTitle="", addLegend=FALSE)
--- a/scripts_R/Metadata_subsetBLSM.R Mon Oct 02 12:37:55 2017 +0100 +++ b/scripts_R/Metadata_subsetBLSM.R Mon Oct 02 15:32:51 2017 +0100 @@ -12,17 +12,17 @@ par(family="Arial") #pdf(file="data/country_distribution_BL.pdf") -pdf(file="../data/results/country_distribution.pdf") +pdf(file="../data/results/country_distribution.pdf", pointsize=12, width=6, height=4) PlotCountryCounts(df) dev.off() -postscript(file="../data/results/country_distribution.eps") +postscript(file="../data/results/country_distribution.eps", pointsize=12, width=6, height=4) PlotCountryCounts(df) dev.off() -pdf(file="../data/results/year_distribution.pdf", width=6, height=4) +pdf(file="../data/results/year_distribution.pdf", width=6, height=4, pointsize=12) PlotYearDistribution(df) dev.off() -postscript("../data/results/year_distribution.eps", width=10) +postscript("../data/results/year_distribution.eps", width=10, pointsize=12) PlotYearDistribution(df) dev.off() #PlotBarChart(df, cat="Year", ordercat="REGION", mincount=10) @@ -33,10 +33,10 @@ levels(df$Language)[which(levels(df$Language)=="Lesser Antillean Creole French")]="Lesser Antil. Creole French" df$Language[which(df$Language=="Lesser Antillean Creole French")] = "Lesser Antil. Creole French" df$REGION[which(df$Country=="French Guiana")] = "South America" -pdf(file="../data/results/language_distribution.pdf") +pdf(file="../data/results/language_distribution.pdf", pointsize=12) PlotBarChart(df, cat="Language", ordercat="Region", mincount=10) dev.off() -postscript("../data/results/language_distribution.eps", width=8, height=10) +postscript("../data/results/language_distribution.eps", width=8, height=10, pointsize=12) PlotBarChart(df, cat="Language", ordercat="Region", mincount=10) dev.off() @@ -128,5 +128,5 @@ g = g+guides(fill = guide_legend(title = "Region"))+theme(legend.position="top",legend.title = element_text(size=9),legend.text = element_text(size=9)) g = g+theme(panel.border = element_rect(colour = "white"),strip.background=element_rect(fill="white"),strip.text.x = element_blank()) #g = g+theme(axis.text.y = element_text(colour = ddata$labels$col)) -ggsave('../data/results/clusters_top3.pdf',plot=g) -ggsave('../data/results/clusters_top3.eps',plot=g) +ggsave('../data/results/clusters_top3.pdf',plot=g, pointsize=12) +ggsave('../data/results/clusters_top3.eps',plot=g, pointsize=12)
--- a/scripts_R/PlotOutliersCountry.R Mon Oct 02 12:37:55 2017 +0100 +++ b/scripts_R/PlotOutliersCountry.R Mon Oct 02 15:32:51 2017 +0100 @@ -12,12 +12,18 @@ df = read.csv("../data/results/cluster_freq.csv") data = df[,2:dim(df)[2]] +levels(df$labels)[which(levels(df$labels)=="Democratic Republic of the Congo")]="DR Congo" +df$labels[which(df$labels=="Democratic Republic of the Congo")] = "DR Congo" rownames(data) <- df$labels distMahal = as.dist(apply(data, 1, function(i) mahalanobis(data, i, cov = cov(data),tol=1e-18))) hc=hclust(distMahal, method="average") mypal = c("#000000", "#9B0000", "#9B0000", "#9B0000", "#9B0000") clus5 = cutree(hc, 4) -pdf('../data/results/hierarchical_cluster.pdf') +pdf('../data/results/hierarchical_cluster.pdf', pointsize=12) par(mar=c(1,1,1,1)) plot(as.phylo(hc),type="fan",tip.color=mypal[clus5], cex=.5, label.offset=.5) dev.off() +postscript('../data/results/hierarchical_cluster.eps', pointsize=12) +par(mar=c(1,1,1,1)) +plot(as.phylo(hc),type="fan",tip.color=mypal[clus5], cex=.5, label.offset=.5) +dev.off()