selectinputとrenderplot(ggplot)を組み合わせたい。選択した年月を棒グラフにしたい。select year(yil)2009を選択し、month(ay)2を選択した場合、プロットは私の選択を表示する必要があります。これはフィルターのようなものです多分私はこの問題を解決する方法を知りません。データグリッド内の年と月の値、データ画像を共有しました
my ui.R ;
library(shiny)
library(ggplot2)
shinyUI(fluidPage(
titlePanel(title=h4("Norvec Arac Satıs Verisi 2007-2016",align="center")),
sidebarLayout(
sidebarPanel(
selectInput("yil","1.Yıl Seçiniz",
choices = list("2007"=1,"2008"=2,"2009"=3,"2010"=4,"2011"=5,"2012"=6,"2013"=7,"2014"=8,"2015"=9,"2016"=10)),
sliderInput("ay","2. Ay Seçiniz",min = 1,max = 12,value = 1,step = 1,
animate = animationOptions(interval=800,loop = FALSE, playButton = "OYNAT", pauseButton = "DUR"))
),
mainPanel(
tabsetPanel(type="tab",
tabPanel("Grafik",plotOutput("bar"))
)
)
)
))
私のserver.R;
library(shiny)
library(ggplot2)
library(dplyr)
shinyServer(function(input,output){
output$bar <- renderPlot({
ggplot(data=carsales,aes(x = Brand, y = Quantity, group = Brand, color = Brand, fill=Brand)) +
geom_bar(stat = "identity")
})
})
光沢のある:
mydata:
mydata:
> head(carsales)
Year Month Brand Quantity
1 2007 1 Toyota 2884
2 2007 1 Volkswagen 2521
3 2007 1 Peugeot 1029
4 2007 1 Ford 870
5 2007 1 Volvo 693
6 2007 1 Skoda 665
リアクティブなデータセットを作成できます
carsales_subset <- reactive({
carsales %>% filter(Year==input$yil, Month==input$ay)
})
次に、これをggplot関数に渡します
output$bar <- renderPlot({
ggplot(data=carsales_subset(),aes(x = Brand, y = Quantity, group = Brand, color = Brand, fill=Brand)) +
geom_bar(stat = "identity")
})
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加