I want to plot a picture with cumulative distribution function (CDF) and probability density function (PDF),which has a unified x-axis and y-axis with respective scale range on the left and right sides. I tried using the sec_axis() in ggplot2, but PR can only draw one line, and the Y-axis of the other line is invalid. What should I do?
new_data <- rnorm(n=100,mean=8000,sd=1000)
new_data <- as.data.frame(new_data)
names(new_data) <- c("CADP")
m1 <- ggplot(new_data,aes(x=CADP))+geom_density()
p1 <- ggplot(new_data, aes(x =CADP))+stat_ecdf(colour="red")+
labs(
x="CADP")
PR <- p1+scale_y_continuous(expand=c(0,0),limits=c(0,1),
sec.axis = sec_axis(~.*4e-04,breaks=seq(0,4e-04,1e-04)))+
geom_density(colour="blue")
