我正在try 生成一个由3个不同的ggploy对象组成的拼接图形.每一个都必须有相同的x轴.我试着做两件事:1)收集图例2)只显示中间地块的y轴标签和底部地块的x轴标签.当我使用

plot_layout(guides = "collect") 

它只收集了两个--仍然给了我两个传说.

第二个我真的不太确定该怎么做.

我使用的代码是:

# Plot each as an object, then combine in the end
#Full
MEAN_full <- ggplot(full_50, mapping = aes(x = tau, y = mean, group = t))+
  geom_path(aes(colour = t))+
  labs(x = bquote(tau*" (s)"),
       y = bquote(gamma*"ln"(tau)(~Omega~ "cm"^2)),
       colour = "Time after \nplating (h)",
       title = "Cu-LFP cell 16 \n 0.5 mAh/cm2")+
  scale_colour_gradient(low = 'blue', high = 'red')+
  theme_classic(base_size = 20)+
  scale_x_continuous(limits = c(10^-6, 10^0),
                     trans = 'log10',
                     breaks=trans_breaks('log10', function(x) 10^x),
                     labels=trans_format('log10', math_format(10^.x)))+
  ylim(0,50)
MEAN_full
#ANode

MEAN_an <- ggplot(anode_50, mapping = aes(x = tau, y = mean, group = t))+
  geom_path(aes(colour = t))+
  labs(x = bquote(tau*" (s)"),
       y = bquote(gamma*"ln"(tau)(~Omega~ "cm"^2)),
       colour = "Time after \nplating (h)",
       title = "Cu-LFP cell 16 \n 0.5 mAh/cm2")+
  scale_colour_gradient(low = 'blue', high = 'red')+
  theme_classic(base_size = 20)+
  scale_x_continuous(limits = c(10^-6, 10^0),
                     trans = 'log10',
                     breaks=trans_breaks('log10', function(x) 10^x),
                     labels=trans_format('log10', math_format(10^.x)))+
  ylim(0,75)
MEAN_an

#Cathode

MEAN_cath <- ggplot(cath_50, mapping = aes(x = tau, y = mean, group = t))+
  geom_path(aes(colour = t))+
  labs(x = bquote(tau*" (s)"),
       y = bquote(gamma*"ln"(tau)(~Omega~ "cm"^2)),
       colour = "Time after \nplating (h)",
       title = "Cu-LFP cell 16 \n 0.5 mAh/cm2")+
  scale_colour_gradient(low = 'blue', high = 'red')+
  theme_classic(base_size = 20)+
  scale_x_continuous(limits = c(10^-6, 10^0),
                     trans = 'log10',
                     breaks=trans_breaks('log10', function(x) 10^x),
                     labels=trans_format('log10', math_format(10^.x)))+
  ylim(0,50)
MEAN_cath




comb <- MEAN_an/MEAN_cath/MEAN_full 
comb
comb <- comb + plot_layout(guides = 'collect')
comb

每个曲线图包含大量数据,但曲线图之间的数据具有完全相同的格式-相同的长度和相同的变量.我很乐意通过邮箱向任何人发送数据,以获得可重复使用的例子. 不带PLOT_Layout():enter image description here

WITH PLOT_Layout():enter image description here

推荐答案

如果没有一个可重现的例子,就很难确定,但我猜这两个图表的 colored颜色 比例限制是不同的.请考虑以下示例:

# Set up two data frames to plot
df1 <- data.frame(x=1:10,y=runif(10))
df2 <- data.frame(x=1:10,y=runif(10,1,2))

不固定界限的图

(ggplot(df1, aes(x,y,color=y)) + geom_point() + scale_color_gradient()+
(ggplot(df2, aes(x,y,color=y)) + geom_point()+ scale_color_gradient()+
  plot_layout(guides="collect")

enter image description here

在确定限制之后:

(ggplot(df1, aes(x,y,color=y)) + geom_point() + scale_color_gradient(limits=c(0,2)))+
  (ggplot(df2, aes(x,y,color=y)) + geom_point()+ scale_color_gradient(limits=c(0,2)))+
  plot_layout(guides="collect")

enter image description here

虽然解决这两个问题(比例和轴)的最佳方法是将数据组合到一个大框架中并使用面. 在这里,你只能看到"最外面"的轴,这就是我认为你想要的图.

dplyr::bind_rows("Group 1"=df1,"Group 2"=df2,.id = "group") |>
  ggplot(aes(x,y,color=y)) + geom_point() + facet_wrap(~group)

enter image description here

R相关问答推荐

R的GG平行坐标图中的排序变量

从API中抓取R数据SON

行式dppr中的变量列名

使用gcuminc,如何使用逗号格式化风险表?

使用sf或terra的LINESTRAING的累积长度

在组中添加值增加和减少的行

从BRM预测价值

使用外部文件分配变量名及其值

如何对2个列表元素的所有组合进行操作?

在ggplot2的框图中绘制所有级别的系数

如何在R库GoogleDrive中完全删除预先授权的Google帐户?

使用Scale_*_MANUAL时在图例中保留未使用的系数级别

Geom_arcbar()中出错:找不到函数";geom_arcbar";

变长向量的矢量化和

是否可以将线性模型的p值添加到tbl_summary中

计算Mean by分组和绑定到R中的数据集

为什么将负值向量提升到分数次方会得到NaN

Broom.Mixed::Augment不适用于Sample::分析

我怎么才能把一盘棋变成一盘棋呢?

将字符变量出现次数不相等的字符框整形为pivot_wider,而不删除重复名称或嵌套字符变量