Introduction

สวัสดีผู้อ่านทุกท่านนะครับ ในการเขียน Introduction อันนี้ขอเขียนไม่เป็นทางการนะครับ พอดีเป็นทางการแล้วรู้สึกอึดอัดน่ะครับ 555 ในส่วนของเนื้อหานี้จะเป็นเนื้อหาเกี่ยวกับการทำ Data Visualization in R ผ่านการใช้ Library(tidyverse) เป็นการบ้านที่ทางพี่ทอย แจฮยอน แห่ง DataRockie ได้ให้ทำเพื่อทบทวนความรู้ ดังนั้นได้โปรดกรุณา Sit down and enjoy.

Hold on! My friend you need to read this.

What is Library(tidyverse) ? ⇒ library(tidyverse) is use for helping you to create and plot graphs. but default theme in R is not impressive for me then I use Library(ggtheme)

1. ต้องการหาความสัมพันธ์ระหว่าง Carat และ Price เพื่อใช้ในการดูแนวโน้มของราคาเพชร

<aside> 💡 Carat ⇒ Continuous, Price ⇒ Continuous

</aside>

## Relation about carat and price from sample
### pick up sample 500 data from diamonds dataframe
set.seed(21)
dia_sample <- sample_frac(diamonds, 0.01)

ggplot(data = dia_sample,
       mapping = aes(x = carat, y = price)) +
  geom_point(shape = 23, fill = "blue") +
  geom_smooth(method = "lm") +
  theme_wsj()

Untitled

2. ต้องการทราบราคากลางของเพชรแต่ละชนิดของการตัด

<aside> 💡 Cut ⇒ Discrete, Price ⇒ Continuous

</aside>

diamonds %>% 
  group_by(cut) %>%
  summarize(
    mean_price = mean(price)
  ) %>%
  ggplot(aes(x = cut, y = mean_price, fill = cut)) +
  geom_col() +
  theme_solarized() +
  labs(title = "Relationship between Cut and Mean of price",
       x = "type of Cut",
       y = "price",
       caption = "Data Source = diamonds From RStudio")

Untitled

3. การตัดของเพชรนั้นมีผลต่อความสะอาดของเพชรหรือไม่

<aside> 💡 Cut ⇒ Discrete, Clarity ⇒ Discrete

</aside>

diamonds %>%
  ggplot(aes(x = cut, y = clarity, color = clarity)) +
  geom_count() +
  theme_solarized()

Untitled