靜態圖表
現在要把一個圖表加到你的儀表板中。
本練習屬於課程
使用 flexdashboard 建立儀表板
練習說明
- 已提供的 R 程式碼區塊
static_plot(在 setup 區塊下面)使用ggplot2建立一個靜態圖。 - 將這個程式碼區塊移到 Trip Durations 圖表中,讓它以圖表形式呈現。
- Knit 並展開 HTML 檢視器。注意圖表相對於容器大小的縮放。試著調整視窗大小並觀察變化。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
{"my_document.Rmd":"---\ntitle: \"Bike Shares Daily\"\noutput: \n flexdashboard::flex_dashboard:\n orientation: columns\n vertical_layout: fill\n---\n\n```{r setup, include=FALSE}\nlibrary(flexdashboard)\nlibrary(readr)\nlibrary(lubridate)\nlibrary(ggplot2)\nlibrary(tidyverse)\n\ntrips_df <- read_csv('https://assets.datacamp.com/production/course_6355/datasets/sanfran_bikeshare_joined_oneday.csv')\n```\n\n```{r static_plot}\n\ntrips_df %>%\n mutate(`Trip Duration (min)` = duration_sec / 60) %>%\n filter(`Trip Duration (min)` <= 60) %>%\n ggplot(aes(x = `Trip Duration (min)`)) +\n theme_bw() +\n geom_histogram(binwidth = 1) +\n ylab('# Trips')\n\n```\n\nOverview\n===================================== \n\nColumn {data-width=650}\n-----------------------------------------------------------------------\n\n### Origins\n\n```{r}\n\n```\n\nColumn {data-width=350}\n-----------------------------------------------------------------------\n\n\n### Trips by Start Time\n\n\n### Trip Durations\n\n\n"}