0

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)
}

My graph

Ambitious Intern
  • 311
  • 1
  • 3
  • 13
  • 1
    When asking for help, you should include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Jul 16 '18 at 18:32
  • You will need to specify the `ylim` in the `hist` function. – Dave2e Jul 16 '18 at 18:39

0 Answers0