2017-03-05 34 views
0

这是我的第一个问题。 Here is the graph. Why my graph does not show numbers on each lines and how can I change left side axis to display numbers rather than exponential sign带DT和光泽的R - dygraphs

另外,我有一些问题有关DTdygraphs光泽
1.我已经在R中读取了我的csv数据,只需运行dygraphs作为附加图像。但是,如果我希望我的图像在鼠标停留在图像上时有一些行数,我该怎么办? 求解
2.此外,我想改变y轴显示数字而不是指数符号。 求解
3.我有一个想法,使用闪亮来显示我的excel数据。因此,我使用带有数据表功能的DT包。另外,如何结合DTdygraphs in shiny。我的意思是当我点击数据表并选择一些行或列时,会显示动态线图。也许还有其他有用和方便的软件包?
4.我在哪里可以学到一些有关闪亮结合DT的参考。

以下是我test.csv输入数据R.

year month company  wp wn  ep en  pa pan npa npan 
1 2015  1  Ch 6497985 1 1471586 2 4833118 3 0 0 
2 2015  1  SK  350 1  0 0  0 0 0 0 
3 2015  2  Ca  0 0 159703 2 36131 5 0 0 
4 2015  2  Ch 88289 1 11227345 3 4305786 2 0 0 
5 2015  2  Fu  0 0 794601 1  0 0 0 0 
6 2015  2  Zu  0 0 70818 1 218310 9 0 0 
7 2015  3  Ca  0 0 93577 1  9586 3 0 0 
8 2015  3  Ch  0 0 11114302 3 1149480 4 0 0 
9 2015  3  Fu  0 0 847562 1  0 0 0 0 
10 2015  3  Zu  0 0 229086 2  0 1 0 0 
11 2015  4  Ca  0 0 59999 1  9375 3 0 0 
12 2015  4  Ch  0 0 9927702 3 16706470 8 0 0 
13 2015  4  Fu  0 0 1000049 1 84655 2 0 0 
14 2015  4  Zu  0 0 173894 1 74300 2 0 0 

也,这里是原始数据

year,month,company,wp,wn,ep,en,pa,pan,npa,npan 
2015,1,Ch,6497985,1,1471586,2,4833118,3,0,0 
2015,1,SK,350,1,0,0,0,0,0,0 
2015,2,Ca,0,0,159703,2,36131,5,0,0 
2015,2,Ch,88289,1,11227345,3,4305786,2,0,0 
2015,2,Fu,0,0,794601,1,0,0,0,0 
2015,2,Zu,0,0,70818,1,218310,9,0,0 
2015,3,Ca,0,0,93577,1,9586,3,0,0 
2015,3,Ch,0,0,11114302,3,1149480,4,0,0 
2015,3,Fu,0,0,847562,1,0,0,0,0 
2015,3,Zu,0,0,229086,2,0,1,0,0 
2015,4,Ca,0,0,59999,1,9375,3,0,0 
2015,4,Ch,0,0,9927702,3,16706470,8,0,0 
2015,4,Fu,0,0,1000049,1,84655,2,0,0 
2015,4,Zu,0,0,173894,1,74300,2,0,0 

我想显示的情节(测试$ EP)通过有序年和月(x轴),并且该剧情包含所有公司。 已解决也许其他用户在将来也有类似的问题。我在下面发布我的方式。

测试$一年< - as.Date(测试$年)
time_series < - XTS(测试$ EP,order.by = $测试一年)
dygraph(time_series,组= $测试公司)

然而,情节并没有显示任何东西。

我的解决办法:

测试$一年< - as.yearmon(测试$一年,“%M%Y)
testre < - dcast(试验,年〜公司,value.var = “EP”)
testre [is.na(testre)] < - 0
test_xts < - XTS(testre [, - 1],order.by = testre $年)
dygraph(test_xts)

非常感谢。
感谢这个平台,所以我可以问问题,并从其他类型的用户学习很多东西。

+0

您能否提供[可重现的示例](http://stackoverflow.com/help/mcve)? – jsb

+0

@Samuel Ok。我编辑了我的问题。请帮帮我。非常感谢。 –

回答

0

这里有些东西可以帮助你入门。假设test是你的数据框架,你应该首先(尽管如此)将long转换为wide。一旦您的闪亮应用程序正在运行,请在您的DT表中选择多行。

library(dygraphs) 
library(xts) 
library(reshape2) 
library(dplyr) 
library(zoo) 
library(shiny) 

ui = fluidPage(

     DT::dataTableOutput("x6"), 
    tags$br(), 
    tags$br(), 
     dygraphOutput("dygraph") 
) 


server = function(input, output) { 

    output$x6 <- DT::renderDataTable(DT::datatable({ 

    test 

    })) 


    output$dygraph <- renderDygraph({ 
    test_select <- test %>% select(year, month, company, ep) 
    test_select <- test_select[c(input$x6_rows_selected), ] 

    test_select_wide <- dcast(test_select, year + month ~ company, value.var="ep") 

    test_select_wide$Date <- as.yearmon(paste(test_select_wide$year, test_select_wide$month, sep = "-")) 
    test_select_wide$Date <- as.Date(test_select_wide$Date) 

    test_select_wide$year <- NULL 
    test_select_wide$month <- NULL 
    #test_select_wide <- test_select_wide[,c(6,1,2,3,4,5)] 

    test_select_wide_xts <- xts(test_select_wide[,-ncol(test_select_wide)], order.by=test_select_wide[,ncol(test_select_wide)]) 

    dygraph(test_select_wide_xts) 
    }) 


} 

shinyApp(ui=ui, server=server) 
+0

谢谢你。然而,我遇到了一些麻烦。 警告:错误< - :变暗[产物1]不匹配对象[0] 堆栈跟踪(最内第一)的长度: 80:投 79:dcast 78:FUNC [C:\用户\ PECHEN \ Desktop/server.R#18] 77:origRenderFunc 76:输出$ dygraph 1:runApp –

+0

@Peter,我明白你的意思。我对我的答案做了一个小小的编辑,但是由于是行:test_select_wide < - dcast(test_select,year + month〜company,value.var =“ep”),这些(警告)错误是正常的,并且因为没有当你最初要求绘制图表时 – MLavoie