Profvis thực chiến
Hãy xem đoạn mã bên phải thực hiện một quy trình phân tích dữ liệu tiêu chuẩn. Nó tải và chọn dữ liệu, vẽ biểu đồ phần dữ liệu quan tâm, và thêm một đường hồi quy.
Bài tập này là một phần của khóa học
Viết mã R hiệu quả
Hướng dẫn bài tập
- Nạp gói
profvis. - Profile đoạn mã.
- Bao toàn bộ mã trong dấu ngoặc nhọn
{. - Bọc phần ngoặc nhọn đó trong một lệnh gọi tới
profvis().
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.
# Load the data set
data(movies, package = "ggplot2movies")
# Load the profvis package
___
# Profile the following code with the profvis function
___
# Load and select data
comedies <- movies[movies$Comedy == 1, ]
# Plot data of interest
plot(comedies$year, comedies$rating)
# Loess regression line
model <- loess(rating ~ year, data = comedies)
j <- order(comedies$year)
# Add fitted line to the plot
lines(comedies$year[j], model$fitted[j], col = "red")
___ ## Remember the closing brackets!