การปรับแต่ง layout

การสร้างกราฟิกแบบโต้ตอบด้วย plotly ใน R

Adam Loy

Statistician, Carleton College

layout()

  • axes: ประเภท, ป้ายกำกับ, tick marks, การแปลง ฯลฯ
  • legend: ตำแหน่ง
  • canvas: เส้นตาราง, สีพื้นหลัง
  • size: ความสูง, ความกว้าง, ระยะขอบ
การสร้างกราฟิกแบบโต้ตอบด้วย plotly ใน R

ป้ายกำกับแกน

winequality %>%
  plot_ly(x = ~free_so2, y = ~total_so2) %>%
  add_markers(marker = list(opacity = 0.2)) 
การสร้างกราฟิกแบบโต้ตอบด้วย plotly ใน R

ป้ายกำกับแกน

winequality %>%
  plot_ly(x = ~free_so2, y = ~total_so2) %>%
  add_markers(marker = list(opacity = 0.2)) %>%
  layout(xaxis = list(title = "Free SO2 (ppm)"),
         yaxis = list(title = "Total SO2 (ppm)"))
การสร้างกราฟิกแบบโต้ตอบด้วย plotly ใน R

ชื่อกราฟ

winequality %>%
  plot_ly(x = ~free_so2, y = ~total_so2) %>%
  add_markers(marker = list(opacity = 0.2)) %>%
  layout(xaxis = list(title = "Free SO2 (ppm)"),
         yaxis = list(title = "Total SO2 (ppm)"),
         title = "Does free SO2 predict total SO2 in wine?")
การสร้างกราฟิกแบบโต้ตอบด้วย plotly ใน R

การแปลงแกน

winequality %>%
  plot_ly(x = ~free_so2, y = ~total_so2) %>%
  add_markers(marker = list(opacity = 0.2)) %>%
  layout(xaxis = list(title = "Free SO2 (ppm, log scale)", type = "log"),
         yaxis = list(title = "Total SO2 (ppm, log scale)", type = "log"),
         title = "Does free SO2 predict total SO2 in wine?")
การสร้างกราฟิกแบบโต้ตอบด้วย plotly ใน R

การปรับแต่งเส้นตาราง

การสร้างกราฟิกแบบโต้ตอบด้วย plotly ใน R

การปรับแต่งเส้นตาราง

winequality %>%
  plot_ly(x = ~free_so2, y = ~total_so2) %>%
  add_markers(marker = list(opacity = 0.5)) %>%
  layout(xaxis = list(title = "Free SO2 (ppm)", zeroline = FALSE),
         yaxis = list(title = "Total SO2 (ppm)", zeroline = FALSE, 
                      showgrid = FALSE))
การสร้างกราฟิกแบบโต้ตอบด้วย plotly ใน R

การปรับแต่ง canvas

24_bgcolor.png

winequality %>%
  plot_ly(x = ~free_so2, y = ~total_so2) %>%
  add_markers(marker = list(opacity = 0.5)) %>%
  layout(xaxis = list(title = "Free SO2 (ppm)"),
         yaxis = list(title = "Total SO2 (ppm)"),
         plot_bgcolor = toRGB("gray90"),

paper_bgcolor = toRGB("skyblue"))
การสร้างกราฟิกแบบโต้ตอบด้วย plotly ใน R

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

การสร้างกราฟิกแบบโต้ตอบด้วย plotly ใน R

Preparing Video For Download...