Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 将比例添加到绘图_R_Ggplot2_Scale - Fatal编程技术网

R 将比例添加到绘图

R 将比例添加到绘图,r,ggplot2,scale,R,Ggplot2,Scale,我想添加一个比例来帮助理解我的ggplot。 为了简化,可复制的数据集是我原始数据集的一部分 library(tibble) library(dplyr) library(ggplot2) df1 <- tribble(~compound, ~group,~matrix, ~min_measure, ~max_measure, ~ref, "BC","Environnement","water",

我想添加一个比例来帮助理解我的ggplot。 为了简化,可复制的数据集是我原始数据集的一部分

library(tibble)
library(dplyr)
library(ggplot2)

df1 <- tribble(~compound, ~group,~matrix, ~min_measure, ~max_measure, ~ref,
               "BC","Environnement","water", 0.1, 2120,"1",
               "BC","Fruit","apple", 0.001, 9.8,"2",
               "BC","Cereals","rice", 0.1, 47.6,"3",
               "IS","Vegetable","Salad", 0.1, 331.7,"4",
               "TL","Environnement","soil" ,3.2*1000, 9.3*1000,"5",
               "TL","Environnement","water" , 0.02*1000, 1.22*1000,"6",
               "FD","Environnement","soil" , 1.6, 10,"7")
df1_b<-df1 %>%group_by(compound,group,matrix)%>%summarize(min=min(min_measure,na.rm = TRUE),max=max(max_measure))

ggplot(df1_b, aes(xmin=min,xmax=max,y=matrix))+
  geom_linerange(size=1.5)+
  scale_y_discrete(limits=rev)+
  scale_x_log10("ng/g",breaks=c(1e-3,1,1000))+
  facet_grid(compound~.,scales="free",space="free",switch="y")+
  theme_classic()+theme(strip.placement="outside",strip.text.y.left=element_text(angle=0))
库(TIBLE)
图书馆(dplyr)
图书馆(GG2)
df1%汇总(最小值=最小值(最小值,na.rm=真),最大值=最大值(最大值))
ggplot(df1_b,aes(xmin=min,xmax=max,y=matrix))+
几何线范围(尺寸=1.5)+
刻度y离散(限值=rev)+
刻度x对数10(“ng/g”,断裂=c(1e-3,11000))+
小平面网格(复合网格,scales=“free”,space=“free”,switch=“y”)+
theme_classic()+主题(strip.placement=“outside”,strip.text.y.left=元素_text(角度=0))
我的代码得到了什么:

我想要的是这样的东西(没有R实现)

我试图在我的第一个ggplot下添加新的绘图,但我没有找到将其他绘图与我的第一个绘图的指定x值对齐的方法


有人知道在ggplot下添加多尺度的方法吗?或者做一些类似于我梦想的最终绘图的事情吗?

这是关于添加对数尺度的吗?你为什么不把这些比例整合到x比例中呢?您可以使用ggh4x软件包ggh4x软件包也有一些邪恶的嵌套刻面选项。但是,如果您真的需要这三个(IMO混淆)比例,可以将它们创建为一个额外的绘图,并添加例如。patchwork@tjebo谢谢你的建议,我真的需要这三个秤,我已经检查过了。我可能应该更仔细地观察,因为我无法将“第一个刻度”与ggplot中的x=1对齐