R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

library(tidyverse)
## Warning: 套件 'tidyverse' 是用 R 版本 4.3.2 來建造的
## Warning: 套件 'ggplot2' 是用 R 版本 4.3.2 來建造的
## Warning: 套件 'readr' 是用 R 版本 4.3.2 來建造的
## Warning: 套件 'forcats' 是用 R 版本 4.3.2 來建造的
## Warning: 套件 'lubridate' 是用 R 版本 4.3.2 來建造的
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.2     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.4     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.0
## ✔ purrr     1.0.2     
## ── 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
library(ggplot2)
library(plotly)
## Warning: 套件 'plotly' 是用 R 版本 4.3.2 來建造的
## 
## 載入套件:'plotly'
## 
## 下列物件被遮斷自 'package:ggplot2':
## 
##     last_plot
## 
## 下列物件被遮斷自 'package:stats':
## 
##     filter
## 
## 下列物件被遮斷自 'package:graphics':
## 
##     layout
data<-read.csv("D:/01成大資料/二下/R語言資料視覺化/4-2/Tree_Data.csv")

Including Plots

You can also embed plots, for example:

## Warning: The `<scale>` argument of `guides()` cannot be `FALSE`. Use "none" instead as
## of ggplot2 3.3.4.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.

#2.boxplot
ggplot(data, aes(x = Species, y = LIG_Imp)) +
  geom_boxplot() +
  labs(x = "Species", y = "Lignin Impact", title = "Boxplot of Lignin Impact by Species")
## Warning: Removed 480 rows containing non-finite values (`stat_boxplot()`).

#3.boxplot
ggplot(data, aes(x = Species, y = Lignin)) +
  geom_boxplot() +
  labs(x = "Species", y = "Lignin Impact", title = "Boxplot of Lignin Impact by Species")
## Warning: Removed 1510 rows containing non-finite values (`stat_boxplot()`).

#4.scatter plot
cleaned_data <- na.omit(data[, c("Species", "AMF", "AMF_Imp")])
ggplot(cleaned_data, aes(x = AMF, y = AMF_Imp, color = Species)) +
  geom_point()  +  
  labs(title = "Scatter Plot of AMF vs AMF_Imp by Species",
       x = "AMF",
       y = "AMF_Imp") +
  facet_wrap(~ Species)

#5.plotly 
filtered_data <- na.omit(data[, c("Lignin", "LIG_Imp", "Species")])

ggplotly(
ggplot(filtered_data, aes(x = Lignin, y = LIG_Imp, color = Species)) +
  geom_point() +
  geom_smooth(method = "lm", se = FALSE,color = "purple") +
  labs(x = "Lignin", y = "LIG_Imp", title = "Scatter Plot of Lignin vs LIG_Imp by Species")
+
  facet_wrap(~ Species))
## `geom_smooth()` using formula = 'y ~ x'
#6.line
cleaned_data <- na.omit(data[, c("Species", "Time", "LIG_Imp")])


ggplot(cleaned_data, aes(x = Time, y = LIG_Imp, color = Species)) +
  geom_line() +
  labs(title = "Line Plot of Time vs LIG_Imp by Species",
       x = "Time",
       y = "LIG_Imp") +
  facet_wrap(~ Species)

#7.density
ggplot(data, aes(x = NSC_Imp, fill = Species)) +
  geom_density(alpha = 0.5) +
  labs(title = "Density Plot of NSC_Imp by Species",
       x = "NSC_Imp",
       y = "Density") +
  facet_wrap(~ Species)
## Warning: Removed 480 rows containing non-finite values (`stat_density()`).

#8.scatter (use species to wrap)
cleaned_data <- na.omit(data[, c("Species", "AMF", "Light")])
ggplot(data, aes(x = Light, y = AMF, color = Species)) +
  geom_point() +
  labs(title = "Scatter Plot of Light vs AMF by Species",
       x = "Phenolics",
       y = "NSC") +
  facet_wrap(~ Species)
## Warning: Removed 1510 rows containing missing values (`geom_point()`).