我正在为地球化学分析绘制蜘蛛图。
我设法分别绘制了不同系列的元素(主要元素和稀土元素),但我想使用facet_grid将它们绘制在一起。我得到的问题是x轴是常见的。我希望有两个独立的x轴,就像我在imgur帖子中所展示的那样: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
发布于 2020-02-21 00:07:30
你能用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).

https://stackoverflow.com/questions/60323329
复制相似问题