Visit: https://www.geocaceres.com/
—————————————————————————————————————————————————————————————————
Take From: https://ourcodingclub.github.io/tutorials/intro-to-r/
Here are (fictional) values of the wingspan (in cm) measured on four different species of birds. Can you produce a bar plot of the mean wingspan for each species and save it to your computer?
#Calculate mean
sparrow_mean <- mean(22,24,21)
kingfisher_mean <- mean(26,23,25)
eagle_mean <- mean(195,201,185)
hummingbird_mean <- mean(8,9,9)
#Asign mean values to vector wingspan
wingspan <- c(sparrow_mean, kingfisher_mean,eagle_mean,hummingbird_mean)
#Asign name to vector bird species
bird_sp <- c("sparrow", "kingfisher", "eage"," hummingbird")
bird_sp <- as.factor(bird_sp) #Turning a factor
class(bird_sp)
## [1] "factor"
wings <- data.frame(bird_sp, wingspan) #Concatenamos en un data frame
png("wingspan_plot.png", width = 800, height = 600)
barplot (wings$wingspan, names.arg=wings$bird_sp,
xlab = "Bird species",
ylab = "Average wingspan (cm)", # adding axis titles
ylim = c(0, 200), # setting the limits of the y axis to fit the eagle
col = "gold" # changing the colour because why not!
)
dev.off()
## png
## 2