2017-12-20 13 views
0

Rでハイチャートを使用して折れ線グラフを作成しましたが、今は週と月に基づいてデータを集計しようとしています。私はオンラインで検索し、Javaで解決に出くわしたと私は私のコードは、現在のチャートのデータセットのスニペットとスナップショット集計データによるハイチャート

コードと同じ使用してR

IDの下

を実装する方法はかなりよく分からない:

以下は

highchart(type = "stock") %>% 
    hc_title(text = paste("Number of cases by diseases over time")) %>% 
    hc_subtitle(text = "This dataset was produced from disease data from 2014 to 2017") %>% 
    hc_add_series_times_values(salmonella_all_subset$date, 
           salmonella_all_subset$Gonorrhea, 
           name = "Gonorrhea") %>% 
    hc_add_series_times_values(salmonella_all_subset$date, 
           salmonella_all_subset$Shigellosis, 
           name = "Shigellosis") %>% 
    hc_add_series_times_values(salmonella_all_subset$date, 
           salmonella_all_subset$`Campylobacteriosis Enteritis`, 
           name = "Campylobacteriosis Enteritis") %>% 
    hc_add_series_times_values(salmonella_all_subset$date, 
           salmonella_all_subset$Chlamydia, 
           name = "Chlamydia") %>% 
    hc_add_series_times_values(salmonella_all_subset$date, 
           salmonella_all_subset$Salmonellosis, 
           name = "Salmonellosis") %>% 

    hc_add_theme(hc_theme_sandsignika()) 




date Campylobacteriosis Enteritis Chlamydia Gonorrhea Salmonellosis Shigellosis 
1/2/2014 1 10 2 1 0 
1/3/2014 2 3 0 1 0 
1/4/2014 0 2 0 0 0 
1/5/2014 0 1 0 0 0 
1/6/2014 3 7 0 0 0 
1/7/2014 1 18 4 0 0 
1/8/2014 1 14 5 0 0 
1/9/2014 0 12 5 0 0 
1/10/2014 0 26 3 0 0 
1/11/2014 0 5 2 0 0 
1/12/2014 1 1 0 1 0 
1/13/2014 0 9 4 0 0 
1/14/2014 0 21 4 0 0 
1/15/2014 1 22 6 0 0 
1/16/2014 0 18 4 0 0 
1/17/2014 0 14 3 0 0 
1/18/2014 0 6 1 0 0 
1/19/2014 0 2 2 0 0 
1/20/2014 1 4 4 1 0 
1/21/2014 0 4 3 0 0 
1/22/2014 1 13 2 0 0 
1/23/2014 0 12 4 0 0 
1/24/2014 0 17 7 0 0 
1/25/2014 0 4 0 2 0 
1/26/2014 0 5 1 0 0 
1/27/2014 0 16 2 0 0 
1/28/2014 2 26 3 0 0 
1/29/2014 0 14 4 0 0 
1/30/2014 0 12 0 0 0 
1/31/2014 0 8 5 0 0 
2/1/2014 0 5 1 1 0 
2/2/2014 1 1 0 0 0 
2/3/2014 2 15 5 1 0 
2/4/2014 0 19 4 1 1 
2/5/2014 1 11 3 1 0 
2/6/2014 0 17 6 0 0 
2/7/2014 0 19 6 0 0 
2/8/2014 0 4 0 0 0 
2/9/2014 0 0 1 1 0 
2/10/2014 1 17 5 0 0 
2/11/2014 0 13 6 0 0 
2/12/2014 1 18 5 0 0 
2/13/2014 1 6 1 0 1 
2/14/2014 1 6 6 0 0 
2/15/2014 0 2 2 0 0 
2/16/2014 1 2 0 1 0 
2/17/2014 0 3 1 1 0 
2/18/2014 0 12 2 0 0 
2/19/2014 0 9 1 0 0 
2/20/2014 0 9 2 0 0 
2/21/2014 0 15 4 0 0 

The actual plot

が、私はそれになりたいかのリンクですが、私は一日、週、月のラジオボタンを追加する必要が

http://jsfiddle.net/X5WbN/20/

答えて

0

を助けるためにlubridateとdlpyrパッケージになりますかなり光沢がある。あなたが必要とする機能は、ここでlubridateからfloor_dateある作業例です

library(shiny) 
library(highcharter) 
library(lubridate) 
library(dplyr) 
df <- read.table(header = TRUE,sep = ",",text = "date,Campylobacteriosis Enteritis,Chlamydia,Gonorrhea,Salmonellosis,Shigellosis 
1/2/2014,1,10,2,1,0 
       1/3/2014,2,3,0,1,0 
       1/4/2014,0,2,0,0,0 
       1/5/2014,0,1,0,0,0 
       1/6/2014,3,7,0,0,0 
       1/7/2014,1,18,4,0,0 
       1/8/2014,1,14,5,0,0 
       1/9/2014,0,12,5,0,0 
       1/10/2014,0,26,3,0,0 
       1/11/2014,0,5,2,0,0 
       1/12/2014,1,1,0,1,0 
       1/13/2014,0,9,4,0,0 
       1/14/2014,0,21,4,0,0 
       1/15/2014,1,22,6,0,0 
       1/16/2014,0,18,4,0,0 
       1/17/2014,0,14,3,0,0 
       1/18/2014,0,6,1,0,0 
       1/19/2014,0,2,2,0,0 
       1/20/2014,1,4,4,1,0 
       1/21/2014,0,4,3,0,0 
       1/22/2014,1,13,2,0,0 
       1/23/2014,0,12,4,0,0 
       1/24/2014,0,17,7,0,0 
       1/25/2014,0,4,0,2,0 
       1/26/2014,0,5,1,0,0 
       1/27/2014,0,16,2,0,0 
       1/28/2014,2,26,3,0,0 
       1/29/2014,0,14,4,0,0 
       1/30/2014,0,12,0,0,0 
       1/31/2014,0,8,5,0,0 
       2/1/2014,0,5,1,1,0 
       2/2/2014,1,1,0,0,0 
       2/3/2014,2,15,5,1,0 
       2/4/2014,0,19,4,1,1 
       2/5/2014,1,11,3,1,0 
       2/6/2014,0,17,6,0,0 
       2/7/2014,0,19,6,0,0 
       2/8/2014,0,4,0,0,0 
       2/9/2014,0,0,1,1,0 
       2/10/2014,1,17,5,0,0 
       2/11/2014,0,13,6,0,0 
       2/12/2014,1,18,5,0,0 
       2/13/2014,1,6,1,0,1 
       2/14/2014,1,6,6,0,0 
       2/15/2014,0,2,2,0,0 
       2/16/2014,1,2,0,1,0 
       2/17/2014,0,3,1,1,0 
       2/18/2014,0,12,2,0,0 
       2/19/2014,0,9,1,0,0 
       2/20/2014,0,9,2,0,0 
       2/21/2014,0,15,4,0,0") 

df$date <- df$date %>% as.character() %>% as.Date(format = "%m/%d/%Y") 

# Define UI for application that draws a histogram 
ui <- fluidPage(

    # Application title 
    titlePanel("Highchart Grouping"), 

    # Sidebar with a slider input for number of bins 
    sidebarLayout(
     sidebarPanel(
     radioButtons("intervall", 
        "Aggregation level:", 
        choices = c("Day" = "day","Month" = "month","Year" = "year")) 
    ), 

     # Show a plot of the generated distribution 
     mainPanel(
     highchartOutput("Plot") 
    ) 
    ) 
) 

# Define server logic required to draw a histogram 
server <- function(input, output) { 
    dta <- reactive({ 
    df %>% 
     group_by(date = floor_date(date,input$intervall)) %>% 
     summarise_if(is.numeric,sum) 
    }) 


    output$Plot <- renderHighchart({ 
    salmonella_all_subset <- dta() 
    highchart(type = "stock") %>% 
     hc_title(text = paste("Number of cases by diseases over time")) %>% 
     hc_subtitle(text = "This dataset was produced from disease data from 2014 to 2017") %>% 
     hc_add_series_times_values(salmonella_all_subset$date, 
            salmonella_all_subset$Gonorrhea, 
            name = "Gonorrhea") %>% 
     hc_add_series_times_values(salmonella_all_subset$date, 
            salmonella_all_subset$Shigellosis, 
            name = "Shigellosis") %>% 
     hc_add_series_times_values(salmonella_all_subset$date, 
            salmonella_all_subset$Campylobacteriosis.Enteritis, 
            name = "Campylobacteriosis Enteritis") %>% 
     hc_add_series_times_values(salmonella_all_subset$date, 
            salmonella_all_subset$Chlamydia, 
            name = "Chlamydia") %>% 
     hc_add_series_times_values(salmonella_all_subset$date, 
            salmonella_all_subset$Salmonellosis, 
            name = "Salmonellosis") %>% 

     hc_add_theme(hc_theme_sandsignika()) 
    }) 
} 

# Run the application 
shinyApp(ui = ui, server = server) 

このことができます願っています!

0

これを解決する簡単な方法のようですが、tabPanelを使用するだけです。日、週、月ごとにタブを設定できます。次に、データが日、週、月に基づいている3つの異なる出力を作成するだけです。

UI:

mainPanel(
    tabsetPanel(
    tabPanel("Day", plotOutput("dayPlot")), 
    tabPanel("Week", plotOutput("weekPlot")), 
    tabPanel("Month", plotOutput("monthPlot")) 
) 
) 

がサーバ:

output$dayPlot <- renderPlot ({ 
#code to aggregate data based upon day 
#lineplot 
}) 

output$weekPlot <- renderPlot ({ 
#code to aggregate data based upon week 
#lineplot 
}) 

output$monthPlot <- renderPlot ({ 
#code to aggregate data based upon month 
#lineplot 
}) 

私はこれをすることができこんにちは日に基づいて集計、週、月