p1 <- ggplot(data = DNA_result, mapping = aes( x= num, y = nd)) +
geom_point(colour = "red") +
xlab( "样本序号") +
ylab("浓度")+
theme(plot.caption = element_text(hjust = 0))+ theme_bw()
p1
p2 <- ggplot(data = DNA_result, mapping = aes( x= num, y = A280)) +
geom_point(colour = "blue") +
xlab( "样本序号") +
ylab("A260/A280")+
theme(plot.caption = element_text(hjust = 0))+ theme_bw() %+replace%
theme(panel.background = element_rect(fill = NA))
p2
double_y_axis <- function(p1, p2){
g1 <- ggplot_gtable(ggplot_build(p1))
g2 <- ggplot_gtable(ggplot_build(p2))
# overlap the panel of 2nd plot on that of 1st plot
pp <- c(subset(g1$layout, name == "panel", se = t:r))
g <- gtable_add_grob(g1, g2$grobs[[which(g2$layout$name == "panel")]], pp$t, pp
R ggplot绘制双纵坐标轴
最新推荐文章于 2024-05-28 09:32:24 发布
本文介绍了如何利用R语言中的ggplot2包创建具有双纵坐标轴的图形,详细阐述了每个步骤,包括设置坐标轴比例、调整标签以及整合两个数据集的技巧。
摘要由CSDN通过智能技术生成