3

ggplot2 を使用する R 光沢のあるアプリを作成しています。このアプリは、ユーザーがアップロードした csv ファイルを取り込み、ggplot2 を使用してそれらをグラフ化します。

私のアプリは、小さな csv 入力に対してうまく機能します (最大 20 行/列まで話しています)。2MB 以上の範囲のファイルのデータの視覚化に役立つアプリを作ろうとしています。

しかし、私の現在の状態では、私のグラフはビッグデータの分析には役に立ちません。問題を再現できるように、コードの一部と相対 csv ファイルへのリンクを投稿します。

データセットの例を次に示します: http://seanlahman.com/baseball-archive/statistics/、バージョン 5.9.1 から何かを選択 – カンマ区切りバージョン

Appearances.csv で X の 'YearID' と Y の 'playerID' をグラフ化してみてください。

ui.R

library(shiny)

dataset <- list('Upload a file'=c(1))

shinyUI(pageWithSidebar(

  headerPanel(''),

  sidebarPanel(
     wellPanel(
         radioButtons('format', 'Format', c('CSV', 'TSV', 'XLSX')),
         uiOutput("radio"),
         fileInput('file', 'Data file')           
      ),

      wellPanel(
          selectInput('xLine', 'X', names(dataset)),
          selectInput('yLine', 'Y', names(dataset),  multiple=T)
      )
  ),
  mainPanel( 
      tabsetPanel(

          tabPanel("Line Graph", plotOutput('plotLine', height="auto"), value="line"),   
          id="tsp"            #id of tab
      )
   )
))

サーバー.R

library(reshape2)
library(googleVis)
library(ggplot2)
library(plyr)
library(scales)
require(xlsx)
require(xlsxjars)
require(rJava)


options(shiny.maxRequestSize=-1)


shinyServer(function(input, output, session) {

data <- reactive({

    if (is.null(input$file))
      return(NULL)
    else if (identical(input$format, 'CSV'))
      return(read.csv(input$file$datapath))
    else if (identical(input$format, 'XLSX'))
      return(read.xlsx2(input$file$datapath, input$sheet))
    else
      return(read.delim(input$file$datapath))
  })

  output$radio <- reactiveUI(function() {
    if (input$format == 'XLSX') {
        numericInput(inputId = 'sheet',
                     label = "Pick Excel Sheet Index",1)
    }
  })

  observe({
    df <- data()
    str(names(df))
    if (!is.null(df)) {


      updateSelectInput(session, 'xLine', choices = names(df))
      updateSelectInput(session, 'yLine', choices = names(df))


    }
  })

output$plotLine <- renderPlot(height=650, units="px", {

    tempX <- input$xLine
    tempY <- input$yLine

    if (is.null(data()))
      return(NULL)
    if (is.null(tempY))
      return(NULL)

    widedata <- subset(data(), select = c(tempX, tempY))
    melted <- melt(widedata, id = tempX)
    p <- ggplot(melted, aes_string(x=names(melted)[1], y="value", group="variable", color="variable")) + geom_line() + geom_point()
    p <- p + opts(axis.text.x=theme_text(angle=45, hjust=1, vjust=1))
    p <- p + labs(title=paste("",tempX," VS ",tempY,""))

    print(p)
  })
})
4

1 に答える 1

2

プロットがデータで非常に混雑している場合、できることがいくつかあります。

  • データを集計します (例: 1 年あたりの平均)。
  • データをサブセット化し、興味のある変数/期間にデータを制限します。または、たとえば 1% をランダムに取得して、データをサブサンプリングします。
  • グラフを再考してください。仮説をカバーしながら、グラフを乱雑にしない代替の視覚化を考え出すようにしてください。複雑なデータセット (野球のデータセットの 8 MB は決して大きくはありませんが) では、スマートな視覚化が有効です。
于 2013-08-08T06:59:06.903 に答える