Ex code to manipulate ecological data

นำเข้าข้อมูล

raw<-read.table("G:\\My Drive\\document for each subject\\senior_project\\67\\to_r.csv", header = T, sep = ",")

เปิดใช้งาน packages ที่เกี่ยวข้อง

library(dplyr)

Attaching package: 'dplyr'
The following objects are masked from 'package:stats':

    filter, lag
The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union
library(ggplot2)

กราฟ Histogram

-เริ่มจาก Histogram แบบไม่ตั้งค่าเพิ่มเติม

raw %>% ggplot(aes(dis_to_water))+geom_histogram()
`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

-Histogram แบบปรับ binwidth เป็น 5

raw %>% ggplot(aes(dis_to_water))+geom_histogram(binwidth = 5)

-ปรับ binwidth เป็น 10 พร้อมกับเขียนชื่อแผนภูมิและชื่อแกน x และ y

raw %>% ggplot(aes(dis_to_water))+geom_histogram(binwidth = 10)+labs(title="Distance to water", y = "Frequency", x = "Distance to water body (m)")

กราฟลูกโป่ง

-สร้างกราฟแสดงตำแหน่งของแปลงที่พบพืช MP จากระยะห่างจากแหล่งน้ำทั้งแนวระนาบและแนวดิ่ง โดยให้ขนาดของจุดใหญ่ขึ้นตามจำนวนต้นไม้ชนิด MP

raw %>% ggplot(aes(x=dis_to_water ,y=high_from_water,
           size = MP
       ))+  
  geom_point()+labs(x="Height from water body (m)", y="Distance from water body (m)")

สร้างกราฟ 3 มิติ

-เปิดใช้งาน package

library(rgl)

-สร้างกราฟ 3 มิติ แสดงความสัมพันธ์ระหว่างระยะห่างจากแหล่งน้ำในแนวระนาบ แนวดิ่ง และจำนวนต้น MP ที่พบ

plot3d(raw$dis_to_water, raw$high_from_water, raw$MP, type="s", size=0.75, lit=FALSE)

หมายเหตุ กราฟ 3 มิติ อาจไม่สามารถแสดงผลลัพทธ์ตรงนี้ได้