comparison Map_shp.R @ 0:985f8839aebd draft default tip

planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/Geom_mean_workflow commit 3f11e193fd9ba5bf0c706cd5d65d6398166776cb
author ecology
date Sat, 25 Nov 2023 15:18:01 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:985f8839aebd
1 library(ggplot2)
2 library(sf)
3 library(dplyr)
4 library(RColorBrewer)
5 library(ggspatial)
6
7 args = commandArgs(trailingOnly=TRUE)
8 if (length(args)==0)
9 {
10 stop("This tool needs at least one argument")
11 }else{
12 dataMap <- args[1]
13 dataEvo <- args[2]
14 title <- args[3]
15 legend <- args[4]
16 coord <- args[5]
17
18 }
19
20 title <- gsub("\\\\n", "\n", title)
21 legend <-gsub("\\\\n", "\n", legend)
22 #read data
23
24 data_map = st_read(dataMap)
25 data_evo = read.delim(dataEvo,header=TRUE,sep="\t")
26
27 #bring together data
28
29 data_fin = bind_cols(data_map,data_evo[2])
30
31
32 # define the data intervals
33 intervals <- cut(data_fin$Evolution_rate, breaks = c(-Inf, 0, 9, 20, Inf), labels = c("Moins de 0", "0 à 10", "10 à 20", "Plus de 20"))
34
35 # Make the map with ggplot2
36
37 if (coord == "true"){
38 ggplot(data_fin) +
39 geom_sf(aes(fill = intervals)) +
40 scale_fill_manual(values = c('#D9F0D3',"#A6DBA0","#5AAE61","#1B7837")) +
41 labs(title = title, fill = legend) +
42 annotation_scale()
43
44 #outuput
45 ggsave("map.pdf", device = "pdf")
46
47 }else{
48 ggplot(data_fin) +
49 geom_sf(aes(fill = intervals)) +
50 scale_fill_manual(values = c('#D9F0D3',"#A6DBA0","#5AAE61","#1B7837")) +
51 labs(title = title, fill = legend) +
52 theme_void()+
53 annotation_scale()
54
55 #outuput
56 ggsave("map.pdf", device = "pdf")
57 }
58
59
60
61
62