# My density plot in R has values beyond 1! How can I fix this? [duplicate]

I'm trying to plot a generalized pareto distribution with fixed initial values "scale" and "shape" to a random sequence of numbers. When I produce the plot with scale=1 and shape=1, I get the density on the y-axis with limits (0,1). If I produce the plot with different parameters (like the ones below), on the y-axis I get density values between (0,2), which obviously don't make sense.

x <- seq(from = 0, to = 5, by = 0.01)
plot(dgpd(x, scale=0.639, shape=-0.255), type="l",xaxt="n",  las=1, ylab="Density", xlab="Exceedances")
axis(1, at=seq(0, 500, by=100), labels = seq(0, 5, by=1))


(the third line was my way to rename the x-axis, it shouldn't matter for my question.)

Could someone replicate this and tell me whether they also get the weird limits? You know how I can fix this? Thanks!

PS: Sorry for the inconvenience, I only thought that there was a problem with MY specifications since for some parameters I had the interval [0,1] and for others [0,2]. Erroneously enough, I was asking what was wrong with my parameters rather than with the density plot and values. But I get it, it's a question that has been asked before, so it's been flagged as duplicate. Moreover, this being my first experience with stackexchange, I can only learn from it. Good day to you all, lads!

• The area under the density between any two points must be less than 1 but it is not true that the density values themselves must be less than 1. May 22, 2016 at 15:11
• 1. You do't mention where the function dgpd comes from. 2. Nothing is wrong there! Only requirement on density is between points May 22, 2016 at 15:12
• You mean the package? It's the {evd} package May 22, 2016 at 15:14
• Thank you both, after your comments I googled a bit and found the (not so intuitive, at least not to me) explanation of densities above 1. May 22, 2016 at 15:26

Just to add a small explanation: as already pointed out in the comments to your question, the density itself can be above 1. The basic requirement is that it integrates to 1, i.e. that if the support of the density is small enough (or the corresponding part of the distribution where values above 1 occur is small enough), then this is not a problem.

As an illustration, consider the following:

library(ggplot2)
library(reshape2)

n = 10000

df <- melt(data.frame(a = runif(n, 0, 2),
b = runif(n, 0, 1),
c = runif(n, 0, 0.5),
d = runif(n, 0, 0.25),
e = runif(n, 0, 0.05)))

ggplot(df, aes(value, fill=variable)) + geom_density(alpha=0.5)


Here, I have generated five different uniformly distributed random variables. What I have varied is the support. a goes from 0 to 2. b goes from 0 to 1, up to e which goes from 0 to 0.05.

Now, the quiz: think of rectangles where one side has length 2, 1, 0.5, 0.25 or 0.05, respectively. How long is the other side of the rectangle if the area of the rectangle must equal to 1? Well, the area of a rectangle is given by area = a*b, so if area = 1, we can calculate the value of the other side. For instance, if one side is 0.05, the other side needs to be 1/0.05 = 20. And this is why sometimes densities go beyond 1, as you can see in this image: • I did google for some time and haven't found an explanation as simple and well put as yours. Thank you! May 22, 2016 at 19:37
• Glad it helped! May 22, 2016 at 19:39