在aes_string(),因子()和Rstudio的闪亮包

在aes_string(),因子()和Rstudio的闪亮包

问题描述:

当我运行下面的代码:在aes_string(),因子()和Rstudio的闪亮包

graph <- ggplot(data = graphData, aes_string(x = input$variable1, y = input$variable1)) 
    graph <- graph + geom_point(aes_string(colour=input$groupVariable)) 

我得到如下图: enter image description here

,因为它不是由不同的分组这是个问题颜色,而是与蓝色的色调。

我想这一点:

enter image description here

我试图用factor(),如下:

graph <- ggplot(data = graphData, aes_string(x = input$variable1, y = input$variable2)) 
    graph <- graph + geom_point(aes_string(colour=factor(input$groupVariable))) 

但是,这只是给了我这样的:

enter image description here

我该怎么做o获得中间图像的图形?

输入是通过其Rstudio的闪亮包通信之间很ui.R和server.R脚本的通道。

+0

@TheTime我也试过,但它不工作。它会说我们创建的中间人变量用于提前存储该因子,但无法找到。 – Ragnar

+0

@TheTime我不确定我遵循,你能详细说明一下吗? – Ragnar

你可以试试下面的代码:

output$plot1 <- renderPlot({ 

graphData[,input$groupVariable] <- factor(graphData[,input$groupVariable]) 

ggplot(graphData, aes_string(x=input$variable1, y=input$variable2, color=input$groupVariable)) + geom_point() 
})