Created
October 30, 2020 10:51
-
-
Save betterdatascience/65223f0dc314a2a65cc49263d5d5af29 to your computer and use it in GitHub Desktop.
001_powerbi_shiny
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(gapminder) | |
library(ggplot2) | |
library(dplyr) | |
library(shiny) | |
ui <- fluidPage( | |
titlePanel("Gapminder explorer", windowTitle = NULL), | |
plotOutput("line") | |
) | |
server <- function(input, output) { | |
output$line <- renderPlot({ | |
data <- gapminder %>% | |
group_by(year, continent) %>% | |
summarise(avgLifeExp = mean(lifeExp)) | |
ggplot(data, aes(x = year, y = avgLifeExp, color = continent)) + | |
geom_line(size = 1.5) + | |
ggtitle("Average life expectrancy per continent through time") + | |
labs(x = "Year", y = "Average life expectancy") + | |
theme_light() + | |
theme( | |
plot.margin = unit(c(2, 1, 1, 1), "cm"), | |
plot.title = element_text(vjust = 13), | |
legend.position = c(0.25, 1.07), legend.direction = "horizontal" | |
) | |
}) | |
} | |
shinyApp(ui = ui, server = server) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment