library(shiny)
library(datasets)
library(data.table)
# Define UI ----
ui <- fluidPage(
# Give the page a title
titlePanel("iris 데이터의 히스토그램, 사분위수, 원형 그래프"),
# Generate a row with a sidebar
sidebarLayout(
# Define the sidebar with one input
sidebarPanel(
selectInput("region", "컬럼:",
choices= colnames(iris[1:4])),
hr(),
helpText("iris 컬럼의 히스토그램 그래프와 사분위수, 원형 그래프 ")
),
# Create a spot for the barplot
mainPanel(
plotOutput("typePlot")
)
)
)
# Define server logic ----
server <-function(input, output) {
# Fill in the spot we created for a plot
output$typePlot <- renderPlot({
par(mar=c(0.1,0.1,1,0.1))
par(mfrow=c(2,2))
# 히스토그램 그래프
hist( iris[ ,input$region ] , col="green",main='아이리스 Histogram',xlab=input$region)
par(new=T)
a = sort(iris[,input$region])
plot(a,dnorm(a,mean=mean(a),sd=sd(a)),type='l',axes=FALSE,ann=FALSE,col='maroon')
# 4분위수 그래프
boxplot( iris[ ,input$region ] , col="medium purple",main='아이리스',xlab=input$region)
# 원형 그래프
x2 = iris[iris$Species=="setosa",]
x3 = iris[iris$Species=="versicolor",]
x4 = iris[iris$Species=="virginica",]
cnt = data.table(setosa=sum(x2[ ,input$region ]),versicolor=sum(x3[ ,input$region ]),virginica=sum(x4[ ,input$region ]))
cnt_labels <- round( cnt/sum(cnt) * 100, 1)
cnt_labels2 <- paste( colnames(cnt_labels) ,cnt_labels ,'%')
pie( t(cnt) , col=rainbow(7), labels=cnt_labels2,main=c('꽃 종류별',input$region))
})
}
# Run the app ----
shinyApp(ui = ui, server = server)
iris.Species
x3 = iris[iris$Species=="setosa",]
x3
x4 = iris[iris$Species=="versicolor",]
x5 = iris[iris$Species=="virginica",]
unique(iris$Species)
x3
sum(iris[ ,"Sepal.Length" ])
cnt = data.table(setosa=sum(x3$Sepal.Length),versicolor=sum(x4$Sepal.Length),virginical=sum(x5$Sepal.Length))
cnt
cnt_labels <- round( cnt/sum(cnt) * 100, 1)
cnt_labels
b = round(x3/sum(x3)*100,1)
paste(colnames(b),b,'%')
pie(t(x3))
iris
cnt_labels2 <- paste( colnames(cnt_labels) ,cnt_labels ,'%')
pie( t(cnt) , col=rainbow(3), labels=cnt_labels2)
--------------------------------------------------------------------------------------------------
꽃 종류별 컬럼별 평균 크기 비율
library(shiny)
library(datasets)
library(data.table)
# Define UI ----
ui <- fluidPage(
# Give the page a title
titlePanel("iris 데이터의 히스토그램, 사분위수, 원형 그래프"),
# Generate a row with a sidebar
sidebarLayout(
# Define the sidebar with one input
sidebarPanel(
selectInput("region", "컬럼:",
choices= colnames(iris[1:4])),
hr(),
helpText("iris 컬럼의 히스토그램 그래프와 사분위수, 원형 그래프 ")
),
# Create a spot for the barplot
mainPanel(
plotOutput("typePlot")
)
)
)
# Define server logic ----
server <-function(input, output) {
# Fill in the spot we created for a plot
output$typePlot <- renderPlot({
par(mar=c(0.1,0.1,1,0.1))
par(mfrow=c(2,2))
# 히스토그램 그래프
hist( iris[ ,input$region ] , col="green",main='아이리스 Histogram',xlab=input$region)
par(new=T)
a = sort(iris[,input$region])
plot(a,dnorm(a,mean=mean(a),sd=sd(a)),type='l',axes=FALSE,ann=FALSE,col='maroon')
# 4분위수 그래프
boxplot( iris[ ,input$region ] , col="medium purple",main='아이리스',xlab=input$region)
# 원형 그래프
x2 = iris[iris$Species=="setosa",]
x3 = iris[iris$Species=="versicolor",]
x4 = iris[iris$Species=="virginica",]
cnt = data.table(setosa=mean(x2[ ,input$region ]),versicolor=mean(x3[ ,input$region ]),virginica=mean(x4[ ,input$region ]))
cnt_labels <- round( cnt/sum(cnt) * 100, 1)
cnt_labels2 <- paste( colnames(cnt_labels) ,cnt_labels ,'%')
pie( t(cnt) , col=rainbow(7), labels=cnt_labels2,main=c('꽃 종류별',input$region,'평균 크기 비율'))
})
}
# Run the app ----
shinyApp(ui = ui, server = server)