library("ggplot2")
msleep
## # A tibble: 83 x 11
## name genus vore order conservation sleep_total sleep_rem sleep_cycle
## <chr> <chr> <chr> <chr> <chr> <dbl> <dbl> <dbl>
## 1 Cheet… Acin… carni Carn… lc 12.1 NA NA
## 2 Owl m… Aotus omni Prim… <NA> 17 1.8 NA
## 3 Mount… Aplo… herbi Rode… nt 14.4 2.4 NA
## 4 Great… Blar… omni Sori… lc 14.9 2.3 0.133
## 5 Cow Bos herbi Arti… domesticated 4 0.7 0.667
## 6 Three… Brad… herbi Pilo… <NA> 14.4 2.2 0.767
## 7 North… Call… carni Carn… vu 8.7 1.4 0.383
## 8 Vespe… Calo… <NA> Rode… <NA> 7 NA NA
## 9 Dog Canis carni Carn… domesticated 10.1 2.9 0.333
## 10 Roe d… Capr… herbi Arti… lc 3 NA NA
## # ... with 73 more rows, and 3 more variables: awake <dbl>, brainwt <dbl>,
## # bodywt <dbl>
ggplot(data = msleep, aes(x =conservation)) +
geom_bar(fill = "lightblue", colour = "black")
### 單變數:連續型
ggplot(data = msleep, aes(x = sleep_total)) +geom_histogram()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
### 雙變數:連續 vs 連續
ggplot(data = msleep, aes(x =brainwt, y=sleep_cycle)) +
geom_point()
## Warning: Removed 53 rows containing missing values (geom_point).
### 雙變數:離散 vs 連續
ggplot(msleep, aes(x=order, y=sleep_cycle)) +
geom_boxplot()
## Warning: Removed 51 rows containing non-finite values (stat_boxplot).
### 多變量:鑽石銷售總體的關係 ### undone
Note that the echo = FALSE
parameter was added to the code chunk to prevent printing of the R code that generated the plot.