head(Orange)
## Tree age circumference
## 1 1 118 30
## 2 1 484 58
## 3 1 664 87
## 4 1 1004 115
## 5 1 1231 120
## 6 1 1372 142
o <- Orange
У нас є виміри для апельсинових дерев: номер дерева, вік (у днях), розмір ствола (у мм).
Порахувати характеристики:
знайти найбільше дерево на кожен час виміру
Як це зробити?
Спочатку потрібно виділити дерева окремо.
tree1 <- Orange[Orange$Tree == 1,]
tree2 <- Orange[Orange$Tree == 2,]
tree3 <- Orange[Orange$Tree == 3,]
tree4 <- Orange[Orange$Tree == 4,]
tree5 <- Orange[Orange$Tree == 5,]
Коли взагалі відбувались виміри? Як вибрати вектор з цими значеннями?
time <- unique(Orange$age)
time
## [1] 118 484 664 1004 1231 1372 1582
А як перевести це у роки?
round(time/365,2)
## [1] 0.32 1.33 1.82 2.75 3.37 3.76 4.33
Тепер виберемо всі виміри на перший вимір
Orange[Orange$age == 118,]
## Tree age circumference
## 1 1 118 30
## 8 2 118 33
## 15 3 118 30
## 22 4 118 32
## 29 5 118 30
Функція max_tree()
max_tree <- function(age){
}
Давайте подумаємо як написати таку функцію
max_tree <- function(age){
t <- Orange[Orange$age == age,]
m <- max(t$circumference)
n <- t[t$circumference == m,]
return(n$Tree)
}
max_tree(118)
## [1] 2
## Levels: 3 < 1 < 5 < 2 < 4
max_tree(484)
## [1] 2
## Levels: 3 < 1 < 5 < 2 < 4
max_tree(664)
## [1] 4
## Levels: 3 < 1 < 5 < 2 < 4
max_tree(1004)
## [1] 4
## Levels: 3 < 1 < 5 < 2 < 4
max_tree(1231)
## [1] 4
## Levels: 3 < 1 < 5 < 2 < 4
max_tree(1372)
## [1] 4
## Levels: 3 < 1 < 5 < 2 < 4
max_tree(1582)
## [1] 4
## Levels: 3 < 1 < 5 < 2 < 4
Графіки. Як зобразити точки на графіку?
plot.new()
plot.window(xlim = c(0,max(Orange$age)),ylim = range(Orange$circumference))
points(x = Orange$age, y = Orange$circumference,pch=19)
axis(1)
axis(2)
Потрібно розфарбувати значення, щоб бачити різні дерева
plot.new()
plot.window(xlim = c(0,max(Orange$age)),ylim = range(Orange$circumference))
points(x = Orange$age, y = Orange$circumference,pch=19, col = rainbow(5))
axis(1)
axis(2)
ще не зовсім зрозуміло, яке дерево як себе веде
fit = lm(tree1$circumference~tree1$age)
plot(tree1$age,tree1$circumference,xlab="Age",ylab="Circumference",pch=19, col = "blue")
abline(fit)
plot.new()
plot.window(xlim = c(0,3000),ylim = c(0,300))
points(x = tree1$age, y = tree1$circumference,pch=19,col = "blue")
lines(x = tree1$age, y = tree1$circumference, col = "red")
abline(fit)
axis(1)
axis(2)
library(gtrendsR)
t <- gtrends("weather", geo = "UA")
plot(t)
brobots <- gtrends(c("Духлій","Духлий","Dukhliy"), geo = "UA",time = "today 12-m")
plot(brobots)
test <- gtrends(c("Велосипед"), geo = "UA")
plot(test)
test <- gtrends(c("Велосипед", "Сноуборд", "Лыжи"), geo = "UA")
plot(test)
test$interest_by_city
Інформація за Броварами
test <- gtrends(c("Велосипед", "Сноуборд", "Лыжи"), geo = "UA-32")
plot(test)
library(shiny)
runExample("01_hello")
runExample()
library(shiny)
ui <- basicPage("This is a real Shiny app")
server <- function(input, output, session) {}
shinyApp(ui = ui, server = server)
http://zevross.com/blog/2016/04/19/r-powered-web-applications-with-shiny-a-tutorial-and-cheat-sheet-with-40-example-apps/
library(shiny)
#### server
server <- function(input, output, session) {
}
#### user interface
ui <- fluidPage(
titlePanel("App with simple layout"),
sidebarLayout(
sidebarPanel(
"Sidebar"
), #endsidebarpanel
mainPanel(
"This is the main panel"
)#end mainpanel
)# end sidebarlayout
)
shinyApp(ui = ui, server = server)