使用小平面网格绘制不同的 x 轴
Plotting different x-axis using facet grids
我正在绘制蜘蛛图以进行地球化学分析。
我设法分别绘制了不同系列的元素(主要元素和稀土元素),但我想使用 facet_grid 将它们绘制在一起。我遇到的问题是 x 轴很常见。我想要两个独立的 x 轴,就像我在 imgur post 中显示的那样:https://imgur.com/a/7YnPio1
我写了关于我所取得的成就的注释代码:
library(readxl)
library(tidyr)
library(dplyr)
library(ggplot2)
data <- read_excel("Documents/TFB/xlsx_geochimie/solfa_total_tout_ppm.xlsx",
col_types = c("text", "numeric", "numeric",
"numeric", "numeric", "numeric",
"numeric", "numeric", "numeric",
"numeric", "numeric", "numeric", "numeric",
"numeric", "numeric", "numeric",
"numeric", "numeric", "numeric", "numeric",
"numeric", "numeric", "numeric", "numeric",
"numeric", "numeric", "numeric", "numeric", "numeric",
"numeric", "numeric", "numeric", "numeric", "numeric",
"numeric", "numeric", "numeric",
"numeric", "numeric", "numeric", "numeric",
"numeric", "numeric", "numeric", "numeric",
"numeric", "numeric", "numeric",
"numeric", "numeric", "numeric",
"numeric", "numeric", "numeric", "numeric",
"numeric", "numeric", "numeric", "numeric",
"numeric", "numeric", "numeric", "numeric",
"numeric", "numeric", "numeric", "numeric"))
### Vectors containing different geochemical series
vec_maj = c("SiO2","TiO2","Al2O3","FeO","MgO","CaO","Na2O","K2O")
vec_TR = c("La","Ce","Pr","Nd","Sm","Eu","Gd","Tb","Dy","Ho","Er","Tm","Yb","Lu")
vec_tout <- as.character(c(vec_maj,vec_TR))
data.mod <- data[vec_tout]
data.mod$Ech <- data$Ech
### Wide format to long format
data.lf = data %>% select(c(vec_tout,"Ech")) %>%
pivot_longer(-Ech,names_to="Element",values_to="Pourcentage") %>%
mutate(Element=factor(Element,levels=unique(vec_tout)))
### Plotting the series separately
data.maj <- subset(data.lf,data.lf$Element %in% vec_maj)
View(data.maj)
data.TR <- subset(data.lf,data.lf$Element %in% vec_TR)
ggplot(data=data.maj,mapping=aes(x=Element,y=Pourcentage,colour=Ech))+
geom_point()+geom_line(aes(group=Ech))+scale_y_log10()
ggplot(data=data.TR,mapping=aes(x=Element,y=Pourcentage,colour=Ech))+
geom_point()+geom_line(aes(group=Ech))+scale_y_log10()
# Plotting the series together, x-axis scales does not split :-(
data.lf$Type <- ifelse(data.lf$Element %in% vec_maj,"Major","REE")
ggplot(data=data.lf,mapping=aes(x=Element,y=Pourcentage,colour=Ech))+
geom_point()+geom_line(aes(group=Ech))+scale_y_log10()+facet_grid(Type~.,scales="free")
您可以在这里下载我的数据集:google drive
您可以使用 facet_wrap
而不是 facet_grid
吗?
ggplot(data.lf, mapping = aes(x = Element, y = Pourcentage, colour = Ech)) +
geom_point() +
geom_line(aes(group = Ech)) +
scale_y_log10() +
facet_wrap(Type ~ ., ncol = 1, scales = "free")
# Warning: Removed 8 rows containing missing values (geom_point).
我正在绘制蜘蛛图以进行地球化学分析。
我设法分别绘制了不同系列的元素(主要元素和稀土元素),但我想使用 facet_grid 将它们绘制在一起。我遇到的问题是 x 轴很常见。我想要两个独立的 x 轴,就像我在 imgur post 中显示的那样:https://imgur.com/a/7YnPio1
我写了关于我所取得的成就的注释代码:
library(readxl)
library(tidyr)
library(dplyr)
library(ggplot2)
data <- read_excel("Documents/TFB/xlsx_geochimie/solfa_total_tout_ppm.xlsx",
col_types = c("text", "numeric", "numeric",
"numeric", "numeric", "numeric",
"numeric", "numeric", "numeric",
"numeric", "numeric", "numeric", "numeric",
"numeric", "numeric", "numeric",
"numeric", "numeric", "numeric", "numeric",
"numeric", "numeric", "numeric", "numeric",
"numeric", "numeric", "numeric", "numeric", "numeric",
"numeric", "numeric", "numeric", "numeric", "numeric",
"numeric", "numeric", "numeric",
"numeric", "numeric", "numeric", "numeric",
"numeric", "numeric", "numeric", "numeric",
"numeric", "numeric", "numeric",
"numeric", "numeric", "numeric",
"numeric", "numeric", "numeric", "numeric",
"numeric", "numeric", "numeric", "numeric",
"numeric", "numeric", "numeric", "numeric",
"numeric", "numeric", "numeric", "numeric"))
### Vectors containing different geochemical series
vec_maj = c("SiO2","TiO2","Al2O3","FeO","MgO","CaO","Na2O","K2O")
vec_TR = c("La","Ce","Pr","Nd","Sm","Eu","Gd","Tb","Dy","Ho","Er","Tm","Yb","Lu")
vec_tout <- as.character(c(vec_maj,vec_TR))
data.mod <- data[vec_tout]
data.mod$Ech <- data$Ech
### Wide format to long format
data.lf = data %>% select(c(vec_tout,"Ech")) %>%
pivot_longer(-Ech,names_to="Element",values_to="Pourcentage") %>%
mutate(Element=factor(Element,levels=unique(vec_tout)))
### Plotting the series separately
data.maj <- subset(data.lf,data.lf$Element %in% vec_maj)
View(data.maj)
data.TR <- subset(data.lf,data.lf$Element %in% vec_TR)
ggplot(data=data.maj,mapping=aes(x=Element,y=Pourcentage,colour=Ech))+
geom_point()+geom_line(aes(group=Ech))+scale_y_log10()
ggplot(data=data.TR,mapping=aes(x=Element,y=Pourcentage,colour=Ech))+
geom_point()+geom_line(aes(group=Ech))+scale_y_log10()
# Plotting the series together, x-axis scales does not split :-(
data.lf$Type <- ifelse(data.lf$Element %in% vec_maj,"Major","REE")
ggplot(data=data.lf,mapping=aes(x=Element,y=Pourcentage,colour=Ech))+
geom_point()+geom_line(aes(group=Ech))+scale_y_log10()+facet_grid(Type~.,scales="free")
您可以在这里下载我的数据集:google drive
您可以使用 facet_wrap
而不是 facet_grid
吗?
ggplot(data.lf, mapping = aes(x = Element, y = Pourcentage, colour = Ech)) +
geom_point() +
geom_line(aes(group = Ech)) +
scale_y_log10() +
facet_wrap(Type ~ ., ncol = 1, scales = "free")
# Warning: Removed 8 rows containing missing values (geom_point).