I want to draw CDF and PDF plots with different axes. Here is my data;
data<-c(`1979` = 12.03, `1980` = 13.66, `1981` = 14.19, `1982` = 11.7,
`1983` = 11.68, `1984` = 11.78, `1985` = 11.19, `1986` = 12.49,
`1987` = 16.22, `1988` = 11.51, `1989` = 10.52, `1990` = 11.53,
`1991` = 10.5, `1992` = 11.2, `1993` = 12.53, `1994` = 10.17,
`1995` = 11.34, `1996` = 12.22, `1997` = 12.84, `1998` = 13.17,
`1999` = 12.61, `2000` = 11.33, `2001` = 11.47, `2002` = 11.75,
`2003` = 12.52, `2004` = 13.03, `2005` = 11.8, `2006` = 12.78,
`2007` = 10.83, `2008` = 14.72, `2009` = 13.18, `2010` = 11.71,
`2011` = 10.21, `2012` = 14.33, `2013` = 12.83, `2014` = 10.84,
`2015` = 11.97, `2016` = 10.65, `2017` = 11.71, `2018` = 11.61,
`2019` = 13.3, `2020` = 11.71)
my codes:
par(mar = c(5, 4, 4, 4) + 0.3)
plot(ecdf(data), ylab="CDF", xlab="MIWH", main = "y")
par(new = TRUE)
pdf<-dnorm(data, mean(data),sd(data))
plot(data,pdf, col = 3, axes = FALSE, xlab = "", ylab = "")
axis(side = 4, at = pretty(range(pdf)))
mtext("PDF", side = 4, line = 3)
I am getting:
But I desire green points to see like a curve:
I tried curve function, but with it I am not able to add axis of pdf.



type = "l"for lines instead of points inside ofplot(). Or use Thelines()function instead of theplot()function.