Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

関東第3回ゼロはじめるからR言語勉強会ー グラフ

11,036 views

Published on

Published in: Technology, Business

関東第3回ゼロはじめるからR言語勉強会ー グラフ

  1. 1. 第四回R勉強会Rで作った感動したグラフを紹介
  2. 2. 1. plotSepal.Length Sepal.Width Petal.Length Petal.Width Species1 5.1 3.5 1.4 0.2 "setosa"2 4.9 3 1.4 0.2 "setosa"3 4.7 3.2 1.3 0.2 "setosa"4 4.6 3.1 1.5 0.2 "setosa"5 5 3.6 1.4 0.2 "setosa"6 5.4 3.9 1.7 0.4 "setosa"7 4.6 3.4 1.4 0.3 "setosa"8 5 3.4 1.5 0.2 "setosa"9 4.4 2.9 1.4 0.2 "setosa"10 4.9 3.1 1.5 0.1 "setosa"
  3. 3. 1. plotplot(x,y, ...)> plot(iris[,"Sepal.Length"],iris[,"Petal.Length"])
  4. 4. 1. plotplot(iris[,"Sepal.Length"],iris[,"Petal.Length"],xlab = "Sepal Length", ylab = "Petal Length",main = "Iris data: Sepal vs. Petal Length")
  5. 5. 1. plotplot(iris[,"Sepal.Length"],iris[,"Petal.Length"],xlab = "Sepal Length", ylab = "Petal Length",main = "Iris data: Sepal vs. Petal Length",col=c("orange3","seagreen4"))
  6. 6. 1. plotplot(iris[,"Sepal.Length"],iris[,"Petal.Length"],xlab = "Sepal Length", ylab = "Petal Length",main = "Iris data: Sepal vs. Petal Length",col=c("orange3","seagreen4"))par(bty="l",las=1,bg="antiquewhite1")
  7. 7. 1. plotplot(iris[,"Sepal.Length"],iris[,"Petal.Length"],xlab = "Sepal Length", ylab = "Petal Length",main = "Iris data: Sepal vs. Petal Length",col=c("orange3","seagreen4"))legend("bottomright",legend=c("Sepal Length","Petal Length"),fill=c("orange3","seagreen4"),ncol=1,title="Iris data legend")
  8. 8. ●ggplot2でデータフレームは中心になりました● 色と大きさと形でデータの属性を表せる●ggplot2のグラフは三つのレイヤーで作れる:– Data layer (データフレーム)– Graphics layers (点や線など )– Statistic layers●qplotとggplotの関数でグラフを作ります2. ggplot2
  9. 9. 2. ggplot2Sepal.Length Sepal.Width Petal.Length Petal.Width Species1 5.1 3.5 1.4 0.2 "setosa"2 4.9 3 1.4 0.2 "setosa"3 4.7 3.2 1.3 0.2 "setosa"4 4.6 3.1 1.5 0.2 "setosa"5 5 3.6 1.4 0.2 "setosa"6 5.4 3.9 1.7 0.4 "setosa"7 4.6 3.4 1.4 0.3 "setosa"8 5 3.4 1.5 0.2 "setosa"9 4.4 2.9 1.4 0.2 "setosa"10 4.9 3.1 1.5 0.1 "setosa"
  10. 10. 2. ggplot2● qplot(Sepal.Length,Petal.Length,data=iris)● qplot(Sepal.Length,Petal.Length,data=iris,color=Species)● qplot(Sepal.Length,Petal.Length,data=iris,color=Species,size=Petal.Width)● qplot(Sepal.Length,Petal.Length,data=iris,color=Species,size=Petal.Width,alpha=I(0.7))
  11. 11. 2. ggplot2● qplot(Sepal.Length,Petal.Length,data=iris,color=Species)+geom_rug()● qplot(Sepal.Length,Petal.Length,data=iris,color=Species)+geom_line()● qplot(Sepal.Length,Petal.Length,data=iris,color=Species)+stat_smooth()
  12. 12. 2. ggplot2labels vals79 rnorm(mean=0,sd=0) 0.7996605396 rexp(rate=0.3) 9.3830294240 rnorm(mean=1,sd=0.5) 0.9357393194 rnorm(mean=-3,sd=3) 1.1291675200 rnorm(mean=-3,sd=3) 6.1559452245 rnorm(mean=1,sd=0.5) 1.0050954…....> head(xy)> qplot(vals,data=xy,col=labels,fill=labels,alpha=I(.3),size=I(.8),geom="density")
  13. 13. 3. shiny●Node.jsを使って統計的なアプリをWEBにアップことができる● 対話的なデータアプリを目指す●サーバとUIはずっとR言語で作れる
  14. 14. 3. shinyshinyUI(pageWithSidebar(headerPanel(),sidebarPanel(),mainPanel()))headerPanelsidebarPanelmainPanel
  15. 15. 3. shinyshinyUI(pageWithSidebar(headerPanel("Benkyokai app"),...))Benkyoukai app
  16. 16. 3. shinyshinyUI(pageWithSidebar(...sidebarPanel(numericInput(inputId = "n_points",label = "Number points randomized",value=100),...),numericInput
  17. 17. 3. shinyshinyUI(pageWithSidebar(...sidebarPanel(numericInput(inputId = "n_points",label = "Number points randomized",value=100),checkboxInput(inputId = "dnorm",label = "Show normal distribution graph",value = TRUE),...),numericInputcheckboxInput
  18. 18. 3. shinyshinyUI(pageWithSidebar(...sidebarPanel(numericInput(inputId = "n_points",label = "Number points randomized",value=100),checkboxInput(inputId = "dnorm",label = "Show normal distribution graph",value = TRUE),conditionalPanel(condition = "input.dnorm == true",numericInput(inputId = "norm_mean",label = "Mean",value=0),numericInput(inputId = "norm_std_dev",label = "Standard deviation",value=1)),...),numericInputcheckboxInputconditionalPanelnumericInputnumericInput
  19. 19. 3. shinyshinyUI(pageWithSidebar(...),mainPanel(plotOutput(outputId = "main_plot",width="750px", height = "500px"))...))mainPanelPlotOutput
  20. 20. 3. shiny
  21. 21. 3. shinyshinyServer(function(input, output) {output$main_plot <- renderPlot({plot.new()plot.window(c(-3,3),c(0,1),main="fds")axis(2,at=seq(0,1,by=0.2))axis(1,at=seq(-5,5,by=0.5))if(input$dnorm){lines(density(rnorm(input$n_points,input$norm_mean,input$norm_std_dev)),col="blue")}if(input$dexp){lines(density(rexp(input$n_points,input$exp_rate)),col="green")}if(input$dgamma){lines(density(rgamma(input$n_points,input$gamma_shape)),col="red")}})})
  22. 22. 3. shiny
  23. 23. 4. 続きビッグデータを表す:グラフを表す:地理的なデータ:qgraphパッケージbigvisパッケージggmapパッケージ
  24. 24. 一緒にR言語を勉強しましょう!

×