반짝

2017-12-30 6 views
1

에 모자이크 플롯의 채우기를 변경 나는 다음과 같은 반짝 응용 프로그램이 : 지금 두 번째 플롯 대화하고 싶다반짝

library(shiny) 
library(ggplot2) 
library(dplyr) 
library(networkD3) 
library(ggmosaic) 

#Loading data 
Category <- c("Bankpass", "Bankpass", "Bankpass", "Moving", "Moving") 
Subcategory <- c("Stolen", "Lost", "Login", "Address", "New contract") 
Weight <- c(10,20,13,40,20) 
Duration <- as.character(c(0.2,0.4,0.5,0.44,0.66)) 
Silence <- as.character(c(0.1,0.3,0.25,0.74,0.26)) 
df <- data.frame(Category, Subcategory, Weight, Duration, Silence) 

ui <- fluidPage(


    tags$div(class="header", 
     selectInput("measure", "", c("Duration", "Silence")) 
), 

    mainPanel(
    tags$div(class = "dashboard_main", 
      tags$div(class="dashboard_main_left", plotOutput("secondPlot")) 

    ) 
) 

) 
server <- function(input, output){ 

    output$secondPlot <- renderPlot({ 
    ggplot(data = df) + 
     geom_mosaic(aes(weight = Weight, x = product(Category), fill=Duration), 
        offset = 0, na.rm=TRUE) + 
     theme(axis.text.x=element_text(angle=-25, hjust= .1)) + 
     theme(axis.title.x=element_blank()) + 
     scale_fill_manual(values=c("#e8f5e9", "#c8e6c9", "#a5d6a7", "#81c784", "#66bb6a")) 
    }) 
} 

shinyApp(ui = ui, server= server) 

합니다. 따라서 지속 시간을 선택하면 "secondPlot"플롯의 지속 시간이 Duration이어야하고 "Silence"를 선택하면 채우기는 "Silence"이어야합니다.

ggplot(data = df) + 
     geom_mosaic(aes(weight = Weight, x = product(Category), fill=input$measure), 
        offset = 0, na.rm=TRUE) + 
     theme(axis.text.x=element_text(angle=-25, hjust= .1)) + 
     theme(axis.title.x=element_blank()) 

내가 더 이상 색상 그라디언트를 참조 해달라고 :

그러나 나는 그래프의 relevante 코드를 변경할 때. 여기에 무슨 일이 생길지에 대한 생각은 없습니까?

답변

3

geom_mosaic 안에 aes_string을 사용해야합니다. 사용해보기 :

server <- function(input, output){ 
    df$prodcat <- product(df$Category) 
    output$secondPlot <- renderPlot({ 
    ggplot(data = df) + 
     geom_mosaic(aes_string(weight = "Weight", x = "prodcat", fill=input$measure), 
        offset = 0, na.rm=TRUE) + 
     theme(axis.text.x=element_text(angle=-25, hjust= .1)) + 
     theme(axis.title.x=element_blank()) + 
     scale_fill_manual(values=c("#e8f5e9", "#c8e6c9", "#a5d6a7", "#81c784", "#66bb6a")) 
    }) 
} 
관련 문제