Ngày 1: Thực hành vẽ biểu đồ # nhập data

setwd("E:/CONG VIEC/Ky nang ngoai/Xu ly so lieu Bang R/Regression-Book-master_VanLang2023")
t=file.choose()
obe=read.csv(t,header=T)
head(obe)
##   id gender height weight  bmi age  bmc  bmd   fat  lean pcfat
## 1  1      F    150     49 21.8  53 1312 0.88 17802 28600  37.3
## 2  2      M    165     52 19.1  65 1309 0.84  8381 40229  16.8
## 3  3      F    157     57 23.1  64 1230 0.84 19221 36057  34.0
## 4  4      F    156     53 21.8  56 1171 0.80 17472 33094  33.8
## 5  5      M    160     51 19.9  54 1681 0.98  7336 40621  14.8
## 6  6      F    153     47 20.1  52 1358 0.91 14904 30068  32.2

Vẽ Histogram

library(ggplot2)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.2     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ lubridate 1.9.2     ✔ tibble    3.2.1
## ✔ purrr     1.0.1     ✔ tidyr     1.3.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
p=ggplot(data=obe,aes(x=pcfat,fill=gender))+geom_histogram(color="white")
p
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

Vẽ biểu đồ density

Pdensity=ggplot(data=obe,aes(x=pcfat,fill=gender,alpha=0.5))+geom_density(color="white")
Pdensity