如何绘制组合图的常见 y-axis 文本 (ggplot2)
How to plot common y-axis text for combined figure (ggplot2)
我是 R(和 ggplot2)的初学者。
我正在尝试制作 1x3 图,所有三个图的 y 轴比例都相同。
此外,我想删除第二个和第三个绘图的 y 轴的文本和标题。
但是,我意识到在删除轴文本和标题时,第一个图的宽度变得比第二个和第三个图窄。
所以,我的问题是,有没有办法制作一个通用的 y-axis 文本?
(以便所有三个数字具有相同的宽度)
这是我的示例代码和图形,谢谢。
library(ggplot2)
df<-data.frame(x=1:5, y1=runif(5), y2=runif(5), y3=runif(5))
p1<-ggplot()+
geom_line(data=df, aes(x=x, y=y1))+
coord_cartesian(ylim = c(0, 1))
p2<-ggplot()+
geom_line(data=df, aes(x=x, y=y2))+
theme(axis.text.y=element_blank(),
axis.title.y = element_blank(),
axis.ticks.y = element_blank())+
coord_cartesian(ylim = c(0, 1))
p3<-ggplot()+
geom_line(data=df, aes(x=x, y=y3))+
theme(axis.text.y=element_blank(),
axis.title.y = element_blank(),
axis.ticks.y = element_blank())+
coord_cartesian(ylim = c(0, 1))
p<-grid.arrange(p1, p2, p3, ncol=3)
有多种方法。
egg 包中的 ggarrange 可以提供帮助。
library(ggplot2)
library(egg)
df<-data.frame(x=1:5, y1=runif(5), y2=runif(5), y3=runif(5))
p1<-ggplot()+
geom_line(data=df, aes(x=x, y=y1))+
coord_cartesian(ylim = c(0, 1))
p2<-ggplot()+
geom_line(data=df, aes(x=x, y=y2))+
theme(axis.text.y=element_blank(),
axis.title.y = element_blank(),
axis.ticks.y = element_blank())+
coord_cartesian(ylim = c(0, 1))
p3<-ggplot()+
geom_line(data=df, aes(x=x, y=y3))+
theme(axis.text.y=element_blank(),
axis.title.y = element_blank(),
axis.ticks.y = element_blank())+
coord_cartesian(ylim = c(0, 1))
p<-grid.arrange(p1, p2, p3, ncol=3)
p2<-ggarrange(p1, p2,p3, ncol=3)
我是 R(和 ggplot2)的初学者。
我正在尝试制作 1x3 图,所有三个图的 y 轴比例都相同。
此外,我想删除第二个和第三个绘图的 y 轴的文本和标题。
但是,我意识到在删除轴文本和标题时,第一个图的宽度变得比第二个和第三个图窄。
所以,我的问题是,有没有办法制作一个通用的 y-axis 文本? (以便所有三个数字具有相同的宽度)
这是我的示例代码和图形,谢谢。
library(ggplot2)
df<-data.frame(x=1:5, y1=runif(5), y2=runif(5), y3=runif(5))
p1<-ggplot()+
geom_line(data=df, aes(x=x, y=y1))+
coord_cartesian(ylim = c(0, 1))
p2<-ggplot()+
geom_line(data=df, aes(x=x, y=y2))+
theme(axis.text.y=element_blank(),
axis.title.y = element_blank(),
axis.ticks.y = element_blank())+
coord_cartesian(ylim = c(0, 1))
p3<-ggplot()+
geom_line(data=df, aes(x=x, y=y3))+
theme(axis.text.y=element_blank(),
axis.title.y = element_blank(),
axis.ticks.y = element_blank())+
coord_cartesian(ylim = c(0, 1))
p<-grid.arrange(p1, p2, p3, ncol=3)
有多种方法。
egg 包中的 ggarrange 可以提供帮助。
library(ggplot2)
library(egg)
df<-data.frame(x=1:5, y1=runif(5), y2=runif(5), y3=runif(5))
p1<-ggplot()+
geom_line(data=df, aes(x=x, y=y1))+
coord_cartesian(ylim = c(0, 1))
p2<-ggplot()+
geom_line(data=df, aes(x=x, y=y2))+
theme(axis.text.y=element_blank(),
axis.title.y = element_blank(),
axis.ticks.y = element_blank())+
coord_cartesian(ylim = c(0, 1))
p3<-ggplot()+
geom_line(data=df, aes(x=x, y=y3))+
theme(axis.text.y=element_blank(),
axis.title.y = element_blank(),
axis.ticks.y = element_blank())+
coord_cartesian(ylim = c(0, 1))
p<-grid.arrange(p1, p2, p3, ncol=3)
p2<-ggarrange(p1, p2,p3, ncol=3)