-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpiechartMap.R
More file actions
48 lines (38 loc) · 1.72 KB
/
piechartMap.R
File metadata and controls
48 lines (38 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
library(rworldmap)
library(plotrix)
#give path to csv file
# version 1.1
setwd("/path/to/workDirectory/") #give the path to the work directory where you files are and/or where you would like to output files to go
inputfile.name = "spicatum_K4_popAverage.csv"
outputfile.name="spicatum_K4"
print.label = F
pieChartSize = 0.6
inputfile <- read.csv(inputfile.name,header=FALSE, as.is=TRUE)
plot.piechart <- function(admixData, lab, pCS) {
#plots map and axes
worldmap <- getMap(resolution = "low")
plot(worldmap, xlim = c(min(admixData[,2]), max(admixData[,2])), ylim = c(min(admixData[,3]), max(admixData[,3])))
box(which="plot")
axis(1)
axis(2)
bordCol = "black"
chart.data <- admixData[4:ncol(admixData)]
#plots the piecharts, admixData$AverK3_1 etc can be changed and extended if needed, example: admixData$AverK4_1[x],admixData$AverK4_2[x],admixData$AverK4_3[x],admixData$AverK4_4[x]
#Just make sure the column names in your input csv matches those in the for loop!
for (x in 1:nrow(admixData)) {
floating.pie(admixData[x,2], admixData[x,3], unlist(chart.data[x,]),
radius=pCS, col=c("red", "blue", "orange", "green","purple", "brown","darkgrey", "yellow", "darkgreen", "cyan"), lwd = 1, border = bordCol)
}
if (lab) {
#function to put labels in map
for (x in 1:nrow(admixData)) {
text(admixData[x,2], admixData[x,3], labels=admixData[x,1], cex= 0.7, pos = 3, offset = 1)
}
}
}
pdf(file = paste(outputfile.name,".pdf",sep=""), title = outputfile.name, width =10, height = 10)
plot.piechart(inputfile,print.label,pieChartSize)
dev.off()
png(filename = paste(outputfile.name,".png",sep=""),width =1000, height = 1000)
plot.piechart(inputfile,print.label,pieChartSize)
dev.off()