The next part of the code specifies the graph of the trend in life expectancy using ggplot2. Let's look at each piece of code:
# trend output$trend = renderPlot({ thePlot = theData() %>% group_by(continent, year) %>% summarise(meanLife = mean(lifeExp)) %>% ggplot(aes(x = year, y = meanLife, group = continent, colour = continent)) + geom_line() + ggtitle("Graph to show life expectancy by continent over time") if(input$linear){ thePlot = thePlot + geom_smooth(method = "lm") } print(thePlot) })
The first line defines the output as a reactive plot. The second instruction uses chained dplyr instructions, as we saw in Chapter 1, Beginning R and Shiny, first to group the data by continent and year, and then to calculate the ...