可视化 Investment Annual Summary 数据
现在,报告所需的数据都已准备好,您可以开始制作将纳入报告的可视化图表,帮助读者在阅读时直观理解数据。我们先用 investment_annual_summary 数据创建一张折线图。
本练习是课程的一部分
使用 R Markdown 生成报告
练习说明
- 在第一个代码块中,在第
10行的dplyr之后加载ggplot2包。 - 在
investment-annual-summary代码块中,使用investment_annual_summary数据创建一张折线图。 - 将会计年度(
fiscal_year)映射到 x 轴,将投资金额(dollars_in_millions)映射到 y 轴。 - 按
region为图形着色,使最终报告中的折线图能以不同颜色区分各地区。
交互式实操练习
通过完成这段示例代码来试试这个练习。
{"investment_report.Rmd":"---\ntitle: \"Investment Report\"\ndate: \"`r format(Sys.time(), '%d %B %Y')`\"\noutput: html_document\n---\n\n```{r data, include = FALSE}\nlibrary(readr)\nlibrary(dplyr)\n# Load the ggplot2 package here\n\ninvestment_annual_summary <- read_csv(\"https://assets.datacamp.com/production/repositories/5756/datasets/d0251f26117bbcf0ea96ac276555b9003f4f7372/investment_annual_summary.csv\")\ninvestment_services_projects <- read_csv(\"https://assets.datacamp.com/production/repositories/5756/datasets/bcb2e39ecbe521f4b414a21e35f7b8b5c50aec64/investment_services_projects.csv\")\n```\n\n\n## Datasets \n\n### Investment Annual Summary\n\nThe `investment_annual_summary` dataset provides a summary of the dollars in millions provided to each region for each fiscal year, from 2012 to 2018.\n```{r investment-annual-summary}\nggplot(___, aes(___)) +\n ___ +\n labs(\n title = \"Investment Annual Summary\",\n x = \"Fiscal Year\",\n y = \"Dollars in Millions\"\n )\n```\n\n### Investment Projects in Brazil\n\nThe `investment_services_projects` dataset provides information about each investment project from 2012 to 2018. Information listed includes the project name, company name, sector, project status, and investment amounts.\n```{r brazil-investment-projects}\nbrazil_investment_projects <- investment_services_projects %>%\n filter(country == \"Brazil\") \n```\n\n### Investment Projects in Brazil in 2018\n\n```{r brazil-investment-projects-2018}\nbrazil_investment_projects_2018 <- investment_services_projects %>%\n filter(country == \"Brazil\",\n date_disclosed >= \"2017-07-01\",\n date_disclosed <= \"2018-06-30\")\n```\n\n\n"}