Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(shiny)
- runGitHub( "<HW2>", "<momokokashi>")
- library(gapminder)
- library(ggplot2)
- ui <- fluidPage(
- titlePanel("Hans Rosling's Bubble Charts"),
- sidebarLayout(
- position = c("left", "right"), fluid = TRUE,
- sidebarPanel(
- selectInput("var_country", "Country:",
- choices = levels(gapminder$country)),
- sliderInput("var_year", "Year:",
- min = min(gapminder$year),
- max = max(gapminder$year),
- value = min(gapminder$year),
- step = 5,
- animate = animationOptions(interval = 1000,loop = TRUE))
- ),
- mainPanel(
- plotOutput("thisPlot")
- )
- )
- )
- server <- function(input, output) {
- output$thisPlot <- renderPlot({
- TmpX = gapminder[gapminder$year==input$var_year, ]
- idx1 = which(TmpX$country == input$var_country)
- RangePop = range(gapminder$pop)
- ggplot(TmpX, aes(gdpPercap, lifeExp, size = pop,color=continent)) +
- geom_point(alpha=1/2) + ylim(25, 100) +
- geom_text(aes(TmpX$gdpPercap[idx1], TmpX$lifeExp[idx1]),
- label=input$var_country, size=8,col=4) +
- scale_x_log10(limits = range(gapminder$gdpPercap)) +
- scale_size(guide = "none", range = c(1,20)*range(TmpX$pop)/RangePop) +
- theme_classic() +
- labs(x="GDP per capita", y="Life Expectancy")
- })
- }
- shinyApp(ui = ui, server = server)
Add Comment
Please, Sign In to add comment