我正在尝试绘制具有正常曲线和图例的直方图,但空间不足。法线曲线超出绘图区域,并且由于空间有限,图例被迫向上弯曲条形图。
normality_plot <- function(datapoints) {
hist(datapoints[[2]][[1]],freq = F, las = 1,main=paste("Histogram of ", datapoints[[1]][[1]]),
xlab="Value",
border="black",
col=" light blue")
curve(dnorm(x, mean = mean(datapoints[[2]][[1]]), sd = sd(datapoints[[2]][[1]])), add=TRUE, col = "darkblue",lwd=3)
legend(x = "topright",
c(paste("Mean = ", mean(datapoints[[2]][[1]])), paste = "Std = ", "N"),xpd=TRUE)
}