首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用刻面网格绘制不同的x轴

使用刻面网格绘制不同的x轴
EN

Stack Overflow用户
提问于 2020-02-20 23:27:46
回答 1查看 62关注 0票数 1

我正在为地球化学分析绘制蜘蛛图。

我设法分别绘制了不同系列的元素(主要元素和稀土元素),但我想使用facet_grid将它们绘制在一起。我得到的问题是x轴是常见的。我希望有两个独立的x轴,就像我在imgur帖子中所展示的那样:https://imgur.com/a/7YnPio1

我已经写了关于我所取得的成果的注释代码:

代码语言:javascript
复制
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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-02-21 00:07:30

你能用facet_wrap代替facet_grid吗?

代码语言:javascript
复制
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).

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60323329

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档