Tarefa5

Author

Licet Fernanda Calambás Trochez

Published

June 6, 2023

Imagem colocada a partir de link

###O que aprendi? Fazer gráficos de barras bonitos

Gráfico antes da disciplina
library(ggplot2)
library(dplyr)

Attaching package: 'dplyr'
The following objects are masked from 'package:stats':

    filter, lag
The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union
setwd("C:/Users/lisa1/Documents/UFPR/Doutorado/Disci_dados_R/")
barras<-read.csv("Familias.csv",header = TRUE, sep = ",")

p <- ggplot(data=barras, aes(x=reorder(Familia,-num_sps), y=num_sps, fill=Riqueza)) +
  geom_bar(stat="identity", position = "dodge")+
  theme_bw()+
  xlab("Familia") + 
  ylab("Riqueza")+
  coord_flip()

p

Gráfico 1. depois da disciplina
setwd("C:/Users/lisa1/Documents/UFPR/Doutorado/Disci_dados_R/")
barras<-read.csv("Familias.csv",header = TRUE, sep = ",")
library(ggplot2)
library(jpeg)
p2 <- readJPEG("download.jpg")
ggplot(barras, aes(x=reorder(Familia, -num_sps), y=num_sps, fill=Riqueza))+
  geom_bar(width = 0.5, stat="identity", position = position_dodge2())+
  labs(y = "Número de espécies por familia", title = "Número de espécies usadas na restauração da Floresta com Araucária", subtitle = "Comparações por Familia")+
  scale_y_continuous(expand=c(0,0), limits=c(0,207))+
  scale_fill_manual(values = c("#6F99ADFF","#20854EFF"), labels = c("Local", "Regional"))+
  theme_classic()+
  theme(legend.title = element_blank(),
        legend.position = c(0.90, 0.9),
        axis.title.x = element_blank(),
        axis.text.x = element_text(face="italic", angle=30, hjust=1, color= "Black"),
        plot.title = element_text(colour = "Black", size=15))+
  annotation_raster(p2, xmin=30, xmax= 28, ymin = 160, ymax=200)

Gráfico 2. depois da disciplina
dados <- data.frame(
  numero_estudos = c(78,3,3,5,19),
  tipo_restauracao = c('Não avaliada','Em perigo','Vulnerável','Quase ameaçada','Pouco preocupante')
)

head(dados)
  numero_estudos  tipo_restauracao
1             78      Não avaliada
2              3         Em perigo
3              3        Vulnerável
4              5    Quase ameaçada
5             19 Pouco preocupante
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ forcats   1.0.0     ✔ stringr   1.5.0
✔ lubridate 1.9.2     ✔ tibble    3.2.1
✔ purrr     1.0.1     ✔ tidyr     1.3.0
✔ readr     2.1.4     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(ggsci)

vu<-ggplot(dados, aes(x="", y=tipo_restauracao, fill=tipo_restauracao)) +
  geom_bar(width = 1, stat = "identity") +
  labs(title = "Status de ameaça das espécies usadas na restauração da Floresta com Araucária")+
  coord_polar("y", start=0)+
  scale_fill_viridis_d()+
  theme_minimal()+ 
  theme(axis.title = element_blank(),axis.text.y=element_blank(), 
        legend.title = element_blank(),
        legend.position="bottom",
        axis.text.x=element_blank())
vu

###O que aprendi? Fazer mapas de distribução de espécies

# Exercício 2-Utilizando os recursos do banco de dados do GBIF e utilizando o pacote rgbif, apresente a localização de alguma espécie que você estude ou goste. Lembre-se que se a distribuição é muito ampla, os dados vão demorar a carregar, então limitar o número de observações ou escolher uma espécie de distribuição restrita pode ser uma opção!

library(tidyverse)
library(ggmap)
ℹ Google's Terms of Service: <https://mapsplatform.google.com>
ℹ Please cite ggmap if you use it! Use `citation("ggmap")` for details.
library(maps)##tem alguns mapas já previamente feitos

Attaching package: 'maps'

The following object is masked from 'package:purrr':

    map
library(rgbif)
ocorrencia<-occ_search(scientificName="Butia exilata", hasCoordinate=T)

local<-as.data.frame(ocorrencia$data)

library(geobr)
Loading required namespace: sf
biomas <- read_biomes(year=2019, showProgress = FALSE)
Using year 2019
head(biomas)
Simple feature collection with 6 features and 3 fields
Geometry type: MULTIPOLYGON
Dimension:     XY
Bounding box:  xmin: -73.98304 ymin: -33.75115 xmax: -28.84785 ymax: 5.269581
Geodetic CRS:  SIRGAS 2000
      name_biome code_biome year                           geom
1       Amazônia          1 2019 MULTIPOLYGON (((-44.08515 -...
2       Caatinga          2 2019 MULTIPOLYGON (((-41.7408 -2...
3        Cerrado          3 2019 MULTIPOLYGON (((-43.39009 -...
4 Mata Atlântica          4 2019 MULTIPOLYGON (((-48.70814 -...
5          Pampa          5 2019 MULTIPOLYGON (((-52.82472 -...
6       Pantanal          6 2019 MULTIPOLYGON (((-57.75946 -...
library(ggsn)#para colocar barra do norte
Loading required package: grid
#Fazendo mapa
ggplot()+ borders("world", fill = "orchid", colour = "gray",alpha=0.5)+
    geom_sf(data= filter(biomas,name_biome=="Mata Atlântica"),  aes(fill=name_biome, alpha=0.7)) +
    geom_point(data = local,aes(decimalLongitude,y=decimalLatitude),color="red",size=2,alpha=0.5)+
    scale_fill_manual(values = terrain.colors(7))+
    coord_sf(xlim= c(-80,-30), ylim=c(-40,10))+
    theme(legend.position = c(0.8,0.9), legend.background = element_blank(), legend.text=element_text(size=10),
          legend.title = element_blank(),
          legend.key.size = unit(0.4, "cm"),
          panel.grid.major = element_line(color = "darkgray", linetype = "dashed", size = 0.5), 
          panel.background = element_rect(fill = "aliceblue"),
          axis.title = element_blank())+
    guides(fill = guide_legend(nrow = 3), alpha= "none")+
    north(biomas, symbol = 14, location = "topleft") +
    scalebar(biomas, location = "bottomright", dist = 1000, dist_unit = "km",
             transform = TRUE, model = "WGS84")
Warning: The `size` argument of `element_line()` is deprecated as of ggplot2 3.4.0.
ℹ Please use the `linewidth` argument instead.

###O que aprendi? Fazer mapas a partir de shapefiles

library(rgdal)
Loading required package: sp
Please note that rgdal will be retired during 2023,
plan transition to sf/stars/terra functions using GDAL and PROJ
at your earliest convenience.
See https://r-spatial.org/r/2022/04/12/evolution.html and https://github.com/r-spatial/evolution
rgdal: version: 1.6-6, (SVN revision 1201)
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 3.6.2, released 2023/01/02
Path to GDAL shared files: C:/Users/lisa1/AppData/Local/R/win-library/4.3/rgdal/gdal
 GDAL does not use iconv for recoding strings.
GDAL binary built with GEOS: TRUE 
Loaded PROJ runtime: Rel. 9.2.0, March 1st, 2023, [PJ_VERSION: 920]
Path to PROJ shared files: C:/Users/lisa1/AppData/Local/R/win-library/4.3/rgdal/proj
PROJ CDN enabled: FALSE
Linking to sp version:1.6-0
To mute warnings of possible GDAL/OSR exportToProj4() degradation,
use options("rgdal_show_exportToProj4_warnings"="none") before loading sp or rgdal.
library(ggplot2)
library(maptools)
Checking rgeos availability: TRUE
Please note that 'maptools' will be retired during 2023,
plan transition at your earliest convenience;
some functionality will be moved to 'sp'.
library(plyr)
------------------------------------------------------------------------------
You have loaded plyr after dplyr - this is likely to cause problems.
If you need functions from both plyr and dplyr, please load plyr first, then dplyr:
library(plyr); library(dplyr)
------------------------------------------------------------------------------

Attaching package: 'plyr'
The following object is masked from 'package:maps':

    ozone
The following object is masked from 'package:purrr':

    compact
The following objects are masked from 'package:dplyr':

    arrange, count, desc, failwith, id, mutate, rename, summarise,
    summarize
library(sp)
library(raster)

Attaching package: 'raster'
The following object is masked from 'package:ggsn':

    scalebar
The following object is masked from 'package:dplyr':

    select
library(dismo)

Attaching package: 'dismo'
The following object is masked from 'package:ggmap':

    geocode
library (rgdal)

setwd("C:/Users/lisa1/Documents/UFPR/Doutorado/Disci_dados_R/")
col_dpto <-shapefile("shapefiles_colombia/depto.shp")

class(col_dpto)
[1] "SpatialPolygonsDataFrame"
attr(,"package")
[1] "sp"
slotNames(col_dpto)
[1] "data"        "polygons"    "plotOrder"   "bbox"        "proj4string"
col_dpto@data$id = rownames(col_dpto@data)
departamentos.points <- fortify(col_dpto,region = "id")
rgeos version: 0.6-3, (SVN revision 696)
 GEOS runtime version: 3.11.2-CAPI-1.17.2 
 Please note that rgeos will be retired during October 2023,
plan transition to sf or terra functions using GEOS at your earliest convenience.
See https://r-spatial.org/r/2023/05/15/evolution4.html for details.
 GEOS using OverlayNG
 Linking to sp version: 1.6-0 
 Polygon checking: TRUE 
departamentos.df <- join(departamentos.points,col_dpto@data,by = "id")
head(departamentos.df)
      long     lat order  hole piece id group DPTO NOMBRE_DPT        AREA
1 754872.1 1445317     1 FALSE     1  1   1.1   05  ANTIOQUIA 63351855547
2 755883.0 1444990     2 FALSE     1  1   1.1   05  ANTIOQUIA 63351855547
3 756588.8 1445107     3 FALSE     1  1   1.1   05  ANTIOQUIA 63351855547
4 758291.0 1444135     4 FALSE     1  1   1.1   05  ANTIOQUIA 63351855547
5 759752.5 1443540     5 FALSE     1  1   1.1   05  ANTIOQUIA 63351855547
6 760958.2 1442437     6 FALSE     1  1   1.1   05  ANTIOQUIA 63351855547
  PERIMETER HECTARES
1   1963729  6335186
2   1963729  6335186
3   1963729  6335186
4   1963729  6335186
5   1963729  6335186
6   1963729  6335186
class(departamentos.df)
[1] "data.frame"
library(maps)
library(ggmap)
colombia <- ggplot(departamentos.df) + 
  aes(long,lat,group=group) + 
  geom_polygon(fill= "lightgray") +
  geom_path(color="white") +
  coord_equal() +
  theme_void()+
  theme(legend.position = "none")
colombia

library(rgdal)
library(ggplot2)
library(maptools)
library(plyr)
library(sp)
library(raster)
library(dismo)
library (rgdal)

setwd("C:/Users/lisa1/Documents/UFPR/Doutorado/Disci_dados_R/")
col_mun <-shapefile("shapefiles_colombia/mpio.shp")

class(col_mun)
[1] "SpatialPolygonsDataFrame"
attr(,"package")
[1] "sp"
slotNames(col_mun)
[1] "data"        "polygons"    "plotOrder"   "bbox"        "proj4string"
col_mun@data$id = rownames(col_mun@data)
municipios.points <- fortify(col_mun,region = "id")


#transformar o shape de municipios em dataframe
municipios.df <- join(municipios.points,col_mun@data,by = "id")

library(maps)
library(ggmap)
library(tidyverse)
dpto<-ggplot(filter(municipios.df, NOMBRE_DPT=="CAUCA")) + 
  aes(long,lat,group=group) + 
  geom_polygon(fill="lightgreen") +
  geom_path(color="white") +
  coord_equal() +
  theme_void()+
  theme(legend.position = "none")
dpto

mpio<-ggplot(filter(municipios.df, id=="917")) + 
  aes(long,lat,group=group) + 
  geom_polygon(fill="lightblue") +
  geom_path(color="white") +
  coord_equal() +
  theme_void()+
  theme(legend.position = "none")
mpio

###Fazer paneis

library(cowplot)#para fazer paineis

Attaching package: 'cowplot'
The following object is masked from 'package:ggmap':

    theme_nothing
The following object is masked from 'package:lubridate':

    stamp
library(jpeg)
setwd("C:/Users/lisa1/Documents/UFPR/Doutorado/Disci_dados_R/")
img3 <- readJPEG("cafe3.jpg")
cafe<-as.raster(img3)

img<-readJPEG("flecha.jpg")
imgr<-as.raster(img)
imgr2<-imgr

ggdraw()+
  coord_equal(xlim = c(0,40),ylim = c(0,40))+
  annotation_custom(ggplotGrob(mpio),xmin=30,xmax=40, ymin=0,ymax=18)+
  annotation_custom(ggplotGrob(dpto),xmin=15,xmax=27, ymin=10,ymax=25)+
  annotation_custom(ggplotGrob(colombia),xmin=0,xmax=12,ymin = 10,ymax=40)+
  annotation_raster(cafe,xmin =30,xmax = 40,ymin=25,ymax=35)+
  annotation_raster(imgr,xmin =12,xmax = 16,ymin=18,ymax=22)+
  annotation_raster(imgr2,xmin =25,xmax = 30,ymin=10,ymax=15)
Coordinate system already present. Adding new coordinate system, which will
replace the existing one.

Imagem colocada a partir de link