2016-07-21 6 views
0

光沢のあるアプリケーションの入力として次のコードスニペットがあります。光沢のあるアプリケーションで2つのグラフを重ね合わせてみましょう

server.R

library(shiny) 
library(ggplot2) 

#df_filter <- df2[df2$month == input$var,] 

shinyServer(function(input, output){ 

    #Hier output je je plot, let op $myhist is iets wat je teruggeeft 
    output$myhist1 <- renderPlot({ 

    gg <- ggplot(data = df2, aes(x=names, y = number, fill = kind)) + geom_bar(stat="identity") + coord_flip() 
    ggg <- gg + ylim(0,1) + theme(legend.position="left") + xlab("") 

    plot(ggg, height = 100, width = 100) 

    }) 

    output$myhist2 <- renderPlot({ 


    p <- ggplot(data = df3, aes(x=names2, y = number2, group = 1)) + geom_point(size=3, fill="white") 
    pp <- p + xlab("Month") + ylab("Mentioned in job ads") + ggtitle("Demand for R") + geom_line() 
    ppp <- pp + geom_point(aes(x = names2, y = benchmark), colour="red", size = 3) + geom_line(aes(x = names2, y = benchmark), colour = "red") 

    plot(ppp) 

    }) 

}) 

UI.R

library(shiny) 
shinyUI(fluidPage(

    #sample data 1 
    names <- c("R", "Python", "Qlikview", "R", "Python", "Qlikview"), 
    number <- c(0.4, 0.8, 0.3, 0.3, 0.7, 0.2), 
    kind <- c("Programming", "Programming", "Dashboarding","Programming", "Programming", "Dashboarding"), 
    month <- c(1,2,3,1,2,3), 
    df2 <- data.frame(names, number, kind, month), 

    #sample data 2 
    names2 <- c(1,2,3,4,5,6,7,8,9,10,11,12), 
    names2 <- as.factor(names2), 
    number2 <- c(0.33, 0.28, 0.32, 0.23, 0.34, 0.45, 0.32, 0.4, 0.5, 0.6, 0.61, 0.59), 
    benchmark <- c(0.33, 0.28, 0.32, 0.23, 0.34, 0.45, 0.36, 0.5, 0.7, 0.67, 0.69, 0.89), 
    df3 <- data.frame(names2, number2, benchmark), 

    #outlinen title 
    titlePanel(title = "227 panel"), 
    sidebarLayout(
    sidebarPanel(

     #Here you enter the var that you would like to use to filter the data shown in the graph 
     selectInput("var", "Select the month", choices = month), 
     br(), 
     br(), 
     br(), 
     br(), 
     br(), 
     br(), 
     br(), 
     br(), 
     br(), 
     br(), 
     br(), 
     br(), 
     selectInput("var", "Select the month", choices = month), 
     br(), 
     br(), 
     br(), 
     br(), 
     br(), 
     br() 
    ), 

    mainPanel((""), 
       splitLayout(cellHeights = c("50%", "50%"), plotOutput("myhist1"), plotOutput("myhist2"))) 
) 
)) 

このすべての作品が、私は今、私の光沢のあるアプリケーションを実行するとき、私は隣同士に2グラフを取得します。実際には、私はそれらをお互いの上に浮かべて配置したいと思います。どのように私はこれを最善の方法で行うことができますか?

答えて

0

splitLayout(cellHeights = c("50%", "50%")は、それらがお互いに隣り合わせに現れるようにします。 簡単に

mainPanel(
    plotOutput("myhist1"), 
    plotOutput("myhist2") 
) 

あなたが探しているものを提供します。 お互いの上に浮かべることで、ページ上の1つのプロットだけを意味し、ページ上の次のプロットをスクロールすることを意味します。 (1つのプロットオーバーレイ/重ね合わせない)

関連する問題