El objetivo de este escrito es familiarse con el lenguaje de R y RStudio, dando a conocer algunas de las caracterÃsticas y funciones que ambos brindan a quienes lo implementan en sus áreas de trabajo.
edidiv.csv <- read.csv("C:/Users/usuagro/Desktop/R/edidiv.csv.csv")
head(edidiv.csv)
tail(edidiv.csv)
str(edidiv.csv)
'data.frame': 25684 obs. of 5 variables:
$ organisationName: Factor w/ 28 levels "BATS & The Millennium Link",..: 14 14 14 8 8 28 28 28 28 28 ...
$ gridReference : Factor w/ 1938 levels "NT200701","NT200712",..: 1314 569 569 1412 1412 1671 1671 1671 1671 1671 ...
$ year : int 2000 2000 2000 2000 2000 2001 2001 2001 2001 2001 ...
$ taxonName : Factor w/ 1275 levels "Acarospora fuscata",..: 1126 1126 1127 192 193 1202 365 977 472 947 ...
$ taxonGroup : Factor w/ 11 levels "Beetle","Bird",..: 2 2 2 2 2 2 2 2 2 2 ...
head(edidiv.csv$taxonGroup)
[1] Bird Bird Bird Bird Bird Bird
Levels: Beetle Bird Butterfly Dragonfly Flowering.Plants Fungus Hymenopteran Lichen Liverwort Mammal Mollusc
class(edidiv.csv$taxonGroup)
[1] "factor"
edidiv.csv$taxonGroup <- as.factor(edidiv.csv$taxonGroup)
dim(edidiv.csv)
[1] 25684 5
summary(edidiv.csv)
organisationName gridReference year taxonName
Biological Records Centre :6744 NT2673 : 2741 Min. :2000 Maniola jurtina : 1710
RSPB :5809 NT2773 : 2031 1st Qu.:2006 Aphantopus hyperantus: 1468
Butterfly Conservation :3000 NT2873 : 1247 Median :2009 Turdus merula : 1112
Scottish Wildlife Trust :2070 NT2570 : 1001 Mean :2009 Lycaena phlaeas : 972
Conchological Society of Great Britain & Ireland:1998 NT27 : 888 3rd Qu.:2011 Aglais urticae : 959
The Wildlife Information Centre :1860 NT2871 : 767 Max. :2016 Aglais io : 720
(Other) :4203 (Other):17009 (Other) :18743
taxonGroup
Butterfly :9670
Bird :7366
Flowering.Plants:2625
Mollusc :2226
Hymenopteran :1391
Mammal : 960
(Other) :1446
summary(edidiv.csv$taxonGroup)
Beetle Bird Butterfly Dragonfly Flowering.Plants Fungus Hymenopteran
426 7366 9670 421 2625 334 1391
Lichen Liverwort Mammal Mollusc
140 125 960 2226
Beetle <- filter(edidiv.csv, edidiv.csv$taxonGroup == "Beetle")
Bird <- filter(edidiv.csv, edidiv.csv$taxonGroup == "Bird")
Butterfly <- filter(edidiv.csv, edidiv.csv$taxonGroup == "Butterfly")
Dragonfly <- filter(edidiv.csv, edidiv.csv$taxonGroup == "Dragonfly")
Flowering.Plants <- filter(edidiv.csv, edidiv.csv$taxonGroup == "Flowering.Plants")
Fungus <- filter(edidiv.csv, edidiv.csv$taxonGroup == "Fungus")
Hymenopteran <- filter(edidiv.csv, edidiv.csv$taxonGroup == "Hymenopteran")
Lichen <- filter(edidiv.csv, edidiv.csv$taxonGroup == "Lichen")
Liverwort <- filter(edidiv.csv, edidiv.csv$taxonGroup == "Liverwort")
Mammal <- filter(edidiv.csv, edidiv.csv$taxonGroup == "Mammal")
Mollusc <- filter(edidiv.csv, edidiv.csv$taxonGroup == "Mollusc")
a <- length(unique(Beetle$taxonName))
biodiv <- c(a,b,c,d,e,f,g,h,i,j,k)
names(biodiv) <- c("Beetle",
"Bird",
"Butterfly",
"Dragonfly",
"Flowering.Plants",
"Fungus",
"Hymenopteran",
"Lichen",
"Liverwort",
"Mammal",
"Mollusc")
barplot(biodiv)
help(barplot)
help(par)
png("barplot.png", width=1600, height=600)
barplot(biodiv, xlab="Taxa", ylab="Number of species", ylim=c(0,600), cex.names= 1.5, cex.axis=1.5, cex.lab=1.5)
Error in barplot(biodiv, xlab = "Taxa", ylab = "Number of species", ylim = c(0, :
object 'biodiv' not found
taxa <- c("Beetle",
"Bird",
"Butterfly",
"Dragonfly",
"Flowering.Plants",
"Fungus",
"Hymenopteran",
"Lichen",
"Liverwort",
"Mammal",
"Mollusc")
taxa_f <- factor(taxa)
richness <- c(a,b,c,d,e,f,g,h,i,j,k)
Error: object 'a' not found
biodata <- data.frame(taxa_f, richness)
write.csv(biodata, file="biodata.csv")
png("barplot2.png", width=1600, height=600)
barplot(biodata$richness, names.arg=c("Beetle",
"Bird",
"Butterfly",
"Dragonfly",
"Flowering.Plants",
"Fungus",
"Hymenopteran",
"Lichen",
"Liverwort",
"Mammal",
"Mollusc"),
xlab="Taxa", ylab="Number of species", ylim=c(0,600))
Error in barplot(biodata$richness, names.arg = c("Beetle", "Bird", "Butterfly", :
object 'biodata' not found
dev.off()
Error in dev.off() : cannot shut down device 1 (the null device)