Skip to content

Instantly share code, notes, and snippets.

@allatambov
Created March 2, 2021 13:08
Show Gist options
  • Save allatambov/c69a51a9326a1a42db9a36e9e7327344 to your computer and use it in GitHub Desktop.
Save allatambov/c69a51a9326a1a42db9a36e9e7327344 to your computer and use it in GitHub Desktop.
tree <- read.csv("https://allatambov.github.io/rprog/data/firtree.csv", encoding = "UTF-8")
table(tree$ftype)
barplot(table(tree$ftype), col = c("forestgreen", "green4", "springgreen3", "springgreen3"),
main = "Хвойные деревья", xlab = "Виды деревьев", ylab = "Частоты",
axes = FALSE)
axis(2, at = seq(from = 0, to = 350, by = 20))
tab <- table(tree$ftype) / sum(table(tree$ftype)) * 100
tab
barplot(tab, col = c("forestgreen", "green4", "springgreen3", "springgreen3"),
main = "Хвойные деревья", xlab = "Виды деревьев", ylab = "Частоты (в %)",
axes = FALSE)
axis(2, at = seq(from = 0, to = 30, by = 3))
perc <- round(tab, 2)
perc
perc_labs <- paste(perc, "%", sep = "")
p <- barplot(tab, col = c("forestgreen", "green4", "springgreen3", "springgreen3"),
main = "Хвойные деревья", xlab = "Виды деревьев", ylab = "Частоты (в %)",
axes = FALSE)
axis(2, at = seq(from = 0, to = 30, by = 3))
text(x = p, y = perc, labels = perc_labs, pos = 1, col = rep(c("white", "black"), each = 2),
cex = 1.2, font = 2)
pie(perc, col = c("forestgreen", "darkolivegreen1", "springgreen3", "lightseagreen"),
labels = perc_labs)
legend(x = 0.9, y = 1, sort(unique(tree$ftype)),
fill = c("forestgreen", "darkolivegreen1", "springgreen3", "lightseagreen"),
cex = 0.7)
hist(tree$height, col = "lightgreen", main = "Histogram of height", xlab = "Height (in cm)",
breaks = 20, freq = FALSE, xlim = c(0, 400))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment