สถิติกับ geoms

การสร้างภาพข้อมูลระดับกลางด้วย ggplot2

Rick Scavetta

Founder, Scavetta Academy

ggplot2, คอร์ส 2

  • สถิติ
  • พิกัด
  • Facets
  • แนวทางปฏิบัติที่ดีในการแสดงข้อมูล
การสร้างภาพข้อมูลระดับกลางด้วย ggplot2

เลเยอร์สถิติ

  • ฟังก์ชัน 2 ประเภท
    • เรียกใช้ภายใน geom
    • เรียกใช้แบบอิสระ
  • stats_
การสร้างภาพข้อมูลระดับกลางด้วย ggplot2

geom_ <-> stat_

p <- ggplot(iris, aes(x = Sepal.Width))
p + geom_histogram()

geom histogram

การสร้างภาพข้อมูลระดับกลางด้วย ggplot2

geom_ <-> stat_

p <- ggplot(iris, aes(x = Sepal.Width))
p + geom_histogram()
p + geom_bar()

geom histogram

การสร้างภาพข้อมูลระดับกลางด้วย ggplot2

geom_ <-> stat_

p <- ggplot(mtcars, aes(x = factor(cyl),  fill = factor(am))) 
p + geom_bar()
p + stat_count()

การสร้างภาพข้อมูลระดับกลางด้วย ggplot2

ความสัมพันธ์ระหว่าง geom_ และ stat_

stat_ geom_
stat_bin() geom_histogram(), geom_freqpoly()
stat_count() geom_bar()
การสร้างภาพข้อมูลระดับกลางด้วย ggplot2

stat_smooth()

ggplot(iris, aes(x = Sepal.Length, 
                 y = Sepal.Width, 
                 color = Species)) + 
  geom_point() +
  geom_smooth()
geom_smooth() using method = 'loess' and 
formula 'y ~ x'

การสร้างภาพข้อมูลระดับกลางด้วย ggplot2

stat_smooth(se = FALSE)

ggplot(iris, aes(x = Sepal.Length, 
                 y = Sepal.Width, 
                 color = Species)) + 
  geom_point() +
  geom_smooth(se = FALSE)
geom_smooth() using method = 'loess' and 
formula 'y ~ x'

การสร้างภาพข้อมูลระดับกลางด้วย ggplot2

geom_smooth(span = 0.4)

ggplot(iris, aes(x = Sepal.Length, 
                 y = Sepal.Width, 
                 color = Species)) + 
  geom_point() +
  geom_smooth(se = FALSE, span = 0.4)
geom_smooth() using method = 'loess' and 
formula 'y ~ x'

การสร้างภาพข้อมูลระดับกลางด้วย ggplot2

geom_smooth(method = "lm")

ggplot(iris, aes(x = Sepal.Length, 
                 y = Sepal.Width, 
                 color = Species)) + 
  geom_point() +
  geom_smooth(method = "lm", se = FALSE)

การสร้างภาพข้อมูลระดับกลางด้วย ggplot2

geom_smooth(fullrange = TRUE)

ggplot(iris, aes(x = Sepal.Length, 
                 y = Sepal.Width, 
                 color = Species)) + 
  geom_point() +
  geom_smooth(method = "lm", 
              fullrange = TRUE)

การสร้างภาพข้อมูลระดับกลางด้วย ggplot2

ความสัมพันธ์ระหว่าง geom_ และ stat_

stat_ geom_
stat_bin() geom_histogram(), geom_freqpoly()
stat_count() geom_bar()
stat_smooth() geom_smooth()
การสร้างภาพข้อมูลระดับกลางด้วย ggplot2

ฟังก์ชัน stat_ อื่น ๆ

stat_ geom_
stat_boxplot() geom_boxplot()
การสร้างภาพข้อมูลระดับกลางด้วย ggplot2

ฟังก์ชัน stat_ อื่น ๆ

stat_ geom_
stat_boxplot() geom_boxplot()
stat_bindot() geom_dotplot()
stat_bin2d() geom_bin2d()
stat_binhex() geom_hex()
การสร้างภาพข้อมูลระดับกลางด้วย ggplot2

ฟังก์ชัน stat_ อื่น ๆ

stat_ geom_
stat_boxplot() geom_boxplot()
stat_bindot() geom_dotplot()
stat_bin2d() geom_bin2d()
stat_binhex() geom_hex()
stat_contour() geom_contour()
stat_quantile() geom_quantile()
stat_sum() geom_count()
การสร้างภาพข้อมูลระดับกลางด้วย ggplot2

มาฝึกกันเถอะ!

การสร้างภาพข้อมูลระดับกลางด้วย ggplot2

Preparing Video For Download...