因为实习兼职的公司用R,温习如下,示例取自此项目

可视化 libraries

library(readr)
library(ggplot2)
library(dplyr)

导入数据

将csv导入dataset

Read datasets/confirmed_cases_worldwide.csv into confirmed_cases_worldwide

选择部分数据

# Filter for China, from Feb 15

china_after_feb15 <- confirmed_cases_china_vs_world %>%
  filter(is_china == "China", date >= "2020-02-15")

画图

单组数据

# Draw a line plot of cumulative cases vs. date
# Label the y-axis

ggplot(confirmed_cases_worldwide, aes(date, cum_cases)) +
  geom_line() +
  ylab("Cumulative confirmed cases")

多组数据

# Using confirmed_cases_top7_outside_china, draw a line plot of
# cum_cases vs. date, colored by country

ggplot(confirmed_cases_top7_outside_china, aes(date, cum_cases, color = country)) +
  geom_line() +
  ylab("Cumulative confirmed cases")

趋势曲线

# Modify the plot to use a logarithmic scale on the y-axis

plt_not_china_trend_lin +
  scale_y_log10()

`geom_smooth()` using formula 'y ~ x'

R语言练习:https://swirlstats.com/faq.html