Guest User

Untitled

a guest
Nov 18th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. library(shiny)
  2. runGitHub( "<HW2>", "<momokokashi>")
  3. library(gapminder)
  4. library(ggplot2)
  5. ui <- fluidPage(
  6. titlePanel("Hans Rosling's Bubble Charts"),
  7. sidebarLayout(
  8. position = c("left", "right"), fluid = TRUE,
  9. sidebarPanel(
  10. selectInput("var_country", "Country:",
  11. choices = levels(gapminder$country)),
  12. sliderInput("var_year", "Year:",
  13. min = min(gapminder$year),
  14. max = max(gapminder$year),
  15. value = min(gapminder$year),
  16. step = 5,
  17. animate = animationOptions(interval = 1000,loop = TRUE))
  18.  
  19. ),
  20. mainPanel(
  21. plotOutput("thisPlot")
  22. )
  23. )
  24. )
  25.  
  26. server <- function(input, output) {
  27. output$thisPlot <- renderPlot({
  28. TmpX = gapminder[gapminder$year==input$var_year, ]
  29. idx1 = which(TmpX$country == input$var_country)
  30. RangePop = range(gapminder$pop)
  31. ggplot(TmpX, aes(gdpPercap, lifeExp, size = pop,color=continent)) +
  32. geom_point(alpha=1/2) + ylim(25, 100) +
  33. geom_text(aes(TmpX$gdpPercap[idx1], TmpX$lifeExp[idx1]),
  34. label=input$var_country, size=8,col=4) +
  35. scale_x_log10(limits = range(gapminder$gdpPercap)) +
  36. scale_size(guide = "none", range = c(1,20)*range(TmpX$pop)/RangePop) +
  37. theme_classic() +
  38. labs(x="GDP per capita", y="Life Expectancy")
  39. })
  40. }
  41.  
  42. shinyApp(ui = ui, server = server)
Add Comment
Please, Sign In to add comment