I want to overly a scatter plot as below, but the first scatter plot is gone after the second plot is drawn though I wrote par(new = TRUE). Does anybody know how to do?
library(readr)
library(ggplot2)
library(dplyr)
library("data.table")
file <-"1.txt"
df <-fread(file,header=T,data.table=FALSE)
mode(df[,2]) <- "numeric"
mode(df[,3]) <- "numeric"
colnames(df) <- c("ID","Number","Scale")
plot <- ggplot(df,aes(x=df[,3],y=df[,2]))
plot <- plot + geom_point(color="red",size=1)
plot <- plot + theme_bw()
plot <- plot + xlab("Scale")
plot <- plot + ylab("Number")
plot <- plot + theme(panel.border=element_blank(),axis.line=element_line(colour="black"),axis.text=element_text(size=8))
plot <- plot + coord_fixed()
plot
par(new = TRUE)
file2 <-"2.txt"
df <-fread(file2,header=T,data.table=FALSE)
mode(df2[,2]) <- "numeric"
mode(df2[,3]) <- "numeric"
colnames(df2) <- c("ID","Number","Scale")
plot <- ggplot(df2,aes(x=df[,3],y=df[,2]))
plot <- plot + geom_point(color="black",size=1)
plot <- plot + theme_bw()
plot <- plot + xlab("Scale")
plot <- plot + ylab("Number")
plot <- plot + theme(panel.border=element_blank(),axis.line=element_line(colour="black"),axis.text=element_text(size=8))
plot <- plot + coord_fixed()
plot
File 1:
ID Number Scale
1 0.317949 0.351713714
2 0.40617 0.451713593
3 0.224795 0.743477906
4 0.352782 0.171798387
5 0.41111 0.51543521
6 0.38464 0.27841593
File 2:
ID Number Scale
1 0.425495 0.498275794
2 0.317949 0.351713714
3 0.458778 0.435448291
4 0.225754 0.756472645
5 0.352782 0.171798387
6 0.41111 0.51543521
Thank you in advance!

