2016-09-04 7 views
1

Rshinyにプロット設定に関する質問があります。基本的には棒グラフがあり、いくつかの列と同じX値の幅を設定したいと思います。ここ は、コードの簡略化とreproductible例です。変数の列サイズをハイチャート(Rshiny)に設定する

library("shiny") 
library("highcharter") 

data(citytemp) 

ui <- fluidPage(
    h1("Highcharter EXAMPLE"), 
    fluidRow(
     column(width = 8, 
       highchartOutput("hcontainer",height = "500px") 
     ) 
    ) 
) 

server <- function(input, output) { 
    data <- citytemp[,c("month","tokyo","new_york")] 
    output$hcontainer <- renderHighchart({ 
     chart <- highchart() %>% 
      hc_chart(type = "bar") %>% 
      hc_title(text = "Monthly Average Temperature for TOKYO") %>% 
      hc_subtitle(text = "Source: WorldClimate.com") %>% 
      hc_xAxis(categories = c('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 
            'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec')) %>% 
      hc_yAxis(title = list(text = "Temperature (C)")) 

     hc <- chart %>% hc_add_series(yAxis=0,name="Tokyo",data = data$tokyo)%>% 
         hc_plotOptions(bar = list(
          pointWidth=10, 
          dataLabels = list(enabled = TRUE) 
         )) 

     hc <- hc %>% hc_add_series(yAxis=0,name="NY",data = data$new_york)%>% 
      hc_plotOptions(bar = list(
       pointWidth=0, 
       dataLabels = list(enabled = TRUE) 
      )) 

     return(hc) 
}) 
} 

shinyApp(ui = ui, server = server) 

私が調査し、これを行う簡単な方法はhc_plotOptionsを変更することです。しかし、あるシリーズのpointWidthを変更すると、両方に適用されます。希望の幅を1つのシリーズにのみ適用する方法はありますか?ご助力ありがとうございます ! ベスト、Madzia

+1

この例を見て、(AddSeries関数の偶然に中に)私はhighcharterわからないけど、標準highchartsにあなたはシリーズ自体の内部series.pointWidthを変更することができる必要があります。http:/ /jsfiddle.net/41yh2689/ –

答えて

1

追加するときにシリーズ内にpointWidthを追加する必要があります。例えばhc_add_series(pointWidth=10,...

rm(list = ls()) 
library("shiny") 
library("highcharter") 

data(citytemp) 

ui <- fluidPage(
    h1("Highcharter EXAMPLE"), 
    fluidRow(
    column(width = 8,highchartOutput("hcontainer",height = "500px") 
    ) 
) 
) 

server <- function(input, output) { 
    data <- citytemp[,c("month","tokyo","new_york")] 
    output$hcontainer <- renderHighchart({ 
    chart <- highchart() %>% 
     hc_chart(type = "bar") %>% 
     hc_title(text = "Monthly Average Temperature for TOKYO") %>% 
     hc_subtitle(text = "Source: WorldClimate.com") %>% 
     hc_xAxis(categories = c('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 
           'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec')) %>% 
     hc_yAxis(title = list(text = "Temperature (C)")) 

    hc <- chart %>% hc_add_series(pointWidth=10,yAxis=0,name="Tokyo",data = data$tokyo)%>% 
     hc_plotOptions(bar = list(dataLabels = list(enabled = TRUE))) 

    hc <- hc %>% hc_add_series(pointWidth=0,yAxis=0,name="NY",data = data$new_york)%>% 
     hc_plotOptions(bar = list(dataLabels = list(enabled = TRUE))) 

    return(hc) 
    }) 
} 

shinyApp(ui = ui, server = server) 

enter image description here

+0

こんにちは!ご助力ありがとうございます !うまくいく!ベスト、Madzia – Madzia

関連する問題