I am trying to plot a histogram with a normal curve and legend but there isn't enough space. The normal curve goes outside the plot area and the legend is forced to curve up bargraph due to limited space.
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)
}