2

When I run the following code:

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

I get the following graph: enter image description here

Which is problematic because it's not grouped by distinct colors, but rather with shades of blue.

I want this:

enter image description here

I tried to use factor() as in the following:

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

But that just gives me this:

enter image description here

What should I do to get the graph as in the middle image?

Note input is the channel through which Rstudio's Shiny package communicates between it's ui.R and server.R scripts.

Markus Amalthea Magnuson
  • 8,415
  • 4
  • 41
  • 49
Ragnar
  • 169
  • 7
  • @TheTime I also tried that but it doesn't work. It will say that the middle-man variable we created to store the factor at ahead of time cannot be found. – Ragnar Dec 03 '15 at 04:07
  • @TheTime I'm not sure I follow, could you elaborate on that? – Ragnar Dec 03 '15 at 04:29

1 Answers1

1

You can try the following code:

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()
})
Ragnar
  • 169
  • 7
ruchijain90
  • 181
  • 6