Bắt đầu ngayBắt đầu miễn phí

Biểu đồ tĩnh

Bây giờ chúng ta sẽ thêm một biểu đồ vào dashboard.

Bài tập này là một phần của khóa học

Xây dựng Dashboard với flexdashboard

Xem khóa học

Hướng dẫn bài tập

  • Khối mã R static_plot được cung cấp (bên dưới khối thiết lập) chứa mã để tạo một biểu đồ tĩnh duy nhất bằng ggplot2.
  • Di chuyển khối mã này để nó hiển thị như một biểu đồ trong phần Trip Durations.
  • Knit rồi mở rộng cửa sổ xem HTML. Lưu ý kích thước của biểu đồ so với kích thước khung chứa biểu đồ. Hãy thử thay đổi kích thước cửa sổ và quan sát điều gì xảy ra.

Bài tập tương tác thực hành trực tiếp

Hãy thử làm bài tập này bằng cách hoàn thành đoạn mã mẫu này.

{"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"}
Chỉnh sửa và Chạy Mã