Content
Provide some information on art, environment
Provide some information on art, environment
Key techniques for visualization
Data for visualization
Here is some data from Water data:
pcp = read.csv('data/pcp.txt', header=T)
summary(pcp)
## meters.date
## 0 01/01/01: 1
## 0 01/01/02: 1
## 0 01/01/03: 1
## 0 01/01/04: 1
## 0 01/01/07: 1
## 0 01/01/08: 1
## (Other) :7914
# present working directory
getwd()
# change working directory
setwd('.')
# list files
list.files()
# list files that end in '.jpg'
list.files(pattern=glob2rx('*.jpg'))
# file exists
file.exists('test.png')
# Run this chunk only once in your Console
# Do not evaluate when knitting Rmarkdown
# list of packages
Traditionally, you would read a CSV like so:
d = read.csv('../data/r-ecology/species.csv')
d
## species_id genus species taxa
## 1 AB Amphispiza bilineata Bird
## 2 AH Ammospermophilus harrisi Rodent
## 3 AS Ammodramus savannarum Bird
## 4 BA Baiomys taylori Rodent
## 5 CB Campylorhynchus brunneicapillus Bird
## 6 CM Calamospiza melanocorys Bird
## 7 CQ Callipepla squamata Bird
## 8 CS Crotalus scutalatus Reptile
## 9 CT Cnemidophorus tigris Reptile
## 10 CU Cnemidophorus uniparens Reptile
## 11 CV Crotalus viridis Reptile
## 12 DM Dipodomys merriami Rodent
## 13 DO Dipodomys ordii Rodent
## 14 DS Dipodomys spectabilis Rodent
## 15 DX Dipodomys sp. Rodent
## 16 EO Eumeces obsoletus Reptile
## 17 GS Gambelia silus Reptile
## 18 NL Neotoma albigula Rodent
## 19 NX Neotoma sp. Rodent
## 20 OL Onychomys leucogaster Rodent
## 21 OT Onychomys torridus Rodent
## 22 OX Onychomys sp. Rodent
## 23 PB Chaetodipus baileyi Rodent
## 24 PC Pipilo chlorurus Bird
## 25 PE Peromyscus eremicus Rodent
## 26 PF Perognathus flavus Rodent
## 27 PG Pooecetes gramineus Bird
## 28 PH Perognathus hispidus Rodent
## 29 PI Chaetodipus intermedius Rodent
## 30 PL Peromyscus leucopus Rodent
## 31 PM Peromyscus maniculatus Rodent
## 32 PP Chaetodipus penicillatus Rodent
## 33 PU Pipilo fuscus Bird
## 34 PX Chaetodipus sp. Rodent
## 35 RF Reithrodontomys fulvescens Rodent
## 36 RM Reithrodontomys megalotis Rodent
## 37 RO Reithrodontomys montanus Rodent
## 38 RX Reithrodontomys sp. Rodent
## 39 SA Sylvilagus audubonii Rabbit
## 40 SB Spizella breweri Bird
## 41 SC Sceloporus clarki Reptile
## 42 SF Sigmodon fulviventer Rodent
## 43 SH Sigmodon hispidus Rodent
## 44 SO Sigmodon ochrognathus Rodent
## 45 SS Spermophilus spilosoma Rodent
## 46 ST Spermophilus tereticaudus Rodent
## 47 SU Sceloporus undulatus Reptile
## 48 SX Sigmodon sp. Rodent
## 49 UL Lizard sp. Reptile
## 50 UP Pipilo sp. Bird
## 51 UR Rodent sp. Rodent
## 52 US Sparrow sp. Bird
## 53 ZL Zonotrichia leucophrys Bird
## 54 ZM Zenaida macroura Bird
head(d)
## species_id genus species taxa
## 1 AB Amphispiza bilineata Bird
## 2 AH Ammospermophilus harrisi Rodent
## 3 AS Ammodramus savannarum Bird
## 4 BA Baiomys taylori Rodent
## 5 CB Campylorhynchus brunneicapillus Bird
## 6 CM Calamospiza melanocorys Bird
summary(d)
## species_id genus species taxa
## AB : 1 Chaetodipus : 4 sp. :10 Bird :13
## AH : 1 Dipodomys : 4 hispidus : 2 Rabbit : 1
## AS : 1 Reithrodontomys: 4 albigula : 1 Reptile: 9
## BA : 1 Sigmodon : 4 audubonii: 1 Rodent :31
## CB : 1 Onychomys : 3 baileyi : 1
## CM : 1 Peromyscus : 3 bilineata: 1
## (Other):48 (Other) :32 (Other) :38
Better yet, try read_csv:
library(readr)
d = read_csv('../data/r-ecology/species.csv')
d
## Source: local data frame [54 x 4]
##
## species_id genus species taxa
## (chr) (chr) (chr) (chr)
## 1 AB Amphispiza bilineata Bird
## 2 AH Ammospermophilus harrisi Rodent
## 3 AS Ammodramus savannarum Bird
## 4 BA Baiomys taylori Rodent
## 5 CB Campylorhynchus brunneicapillus Bird
## 6 CM Calamospiza melanocorys Bird
## 7 CQ Callipepla squamata Bird
## 8 CS Crotalus scutalatus Reptile
## 9 CT Cnemidophorus tigris Reptile
## 10 CU Cnemidophorus uniparens Reptile
## .. ... ... ... ...
head(d)
## Source: local data frame [6 x 4]
##
## species_id genus species taxa
## (chr) (chr) (chr) (chr)
## 1 AB Amphispiza bilineata Bird
## 2 AH Ammospermophilus harrisi Rodent
## 3 AS Ammodramus savannarum Bird
## 4 BA Baiomys taylori Rodent
## 5 CB Campylorhynchus brunneicapillus Bird
## 6 CM Calamospiza melanocorys Bird
summary(d)
## species_id genus species
## Length:54 Length:54 Length:54
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
## taxa
## Length:54
## Class :character
## Mode :character
Now convert to a dplyr table:
library(readr)
library(dplyr)
d = read_csv('../data/r-ecology/species.csv')
d = tbl_df(d)
d = read_csv('../data/r-ecology/species.csv') %>%
tbl_df()
d = tbl_df(read_csv('../data/r-ecology/species.csv'))
head(d)
## Source: local data frame [6 x 4]
##
## species_id genus species taxa
## (chr) (chr) (chr) (chr)
## 1 AB Amphispiza bilineata Bird
## 2 AH Ammospermophilus harrisi Rodent
## 3 AS Ammodramus savannarum Bird
## 4 BA Baiomys taylori Rodent
## 5 CB Campylorhynchus brunneicapillus Bird
## 6 CM Calamospiza melanocorys Bird
summary(d)
## species_id genus species
## Length:54 Length:54 Length:54
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
## taxa
## Length:54
## Class :character
## Mode :character
glimpse(d)
## Observations: 54
## Variables: 4
## $ species_id (chr) "AB", "AH", "AS", "BA", "CB", "CM", "CQ", "CS", "CT...
## $ genus (chr) "Amphispiza", "Ammospermophilus", "Ammodramus", "Ba...
## $ species (chr) "bilineata", "harrisi", "savannarum", "taylori", "b...
## $ taxa (chr) "Bird", "Rodent", "Bird", "Rodent", "Bird", "Bird",...
library(readr)
library(dplyr)
read_csv('../data/r-ecology/surveys.csv') %>%
select(species_id, year) %>%
#filter(species_id == 'NL') %>%
group_by(species_id, year) %>%
summarize(count = n())
## Source: local data frame [535 x 3]
## Groups: species_id [?]
##
## species_id year count
## (chr) (int) (int)
## 1 AB 1980 5
## 2 AB 1981 7
## 3 AB 1982 34
## 4 AB 1983 41
## 5 AB 1984 12
## 6 AB 1985 14
## 7 AB 1986 5
## 8 AB 1987 35
## 9 AB 1988 39
## 10 AB 1989 31
## .. ... ... ...
d = read_csv('../data/r-ecology/species.csv') %>%
tbl_df()
d = tbl_df(read_csv('../data/r-ecology/species.csv'))
d
## Source: local data frame [54 x 4]
##
## species_id genus species taxa
## (chr) (chr) (chr) (chr)
## 1 AB Amphispiza bilineata Bird
## 2 AH Ammospermophilus harrisi Rodent
## 3 AS Ammodramus savannarum Bird
## 4 BA Baiomys taylori Rodent
## 5 CB Campylorhynchus brunneicapillus Bird
## 6 CM Calamospiza melanocorys Bird
## 7 CQ Callipepla squamata Bird
## 8 CS Crotalus scutalatus Reptile
## 9 CT Cnemidophorus tigris Reptile
## 10 CU Cnemidophorus uniparens Reptile
## .. ... ... ... ...
head(d)
## Source: local data frame [6 x 4]
##
## species_id genus species taxa
## (chr) (chr) (chr) (chr)
## 1 AB Amphispiza bilineata Bird
## 2 AH Ammospermophilus harrisi Rodent
## 3 AS Ammodramus savannarum Bird
## 4 BA Baiomys taylori Rodent
## 5 CB Campylorhynchus brunneicapillus Bird
## 6 CM Calamospiza melanocorys Bird
summary(d)
## species_id genus species
## Length:54 Length:54 Length:54
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
## taxa
## Length:54
## Class :character
## Mode :character
glimpse(d)
## Observations: 54
## Variables: 4
## $ species_id (chr) "AB", "AH", "AS", "BA", "CB", "CM", "CQ", "CS", "CT...
## $ genus (chr) "Amphispiza", "Ammospermophilus", "Ammodramus", "Ba...
## $ species (chr) "bilineata", "harrisi", "savannarum", "taylori", "b...
## $ taxa (chr) "Bird", "Rodent", "Bird", "Rodent", "Bird", "Bird",...