Alexander
Alexander

Reputation: 1005

Smooth a density plot so that it doesn't appear saw toothed

I have made a density plot in R. I want to get rid of the saw tooth pattern and have it be entirely smooth. The reason that it appears saw tooth is because the values of x$PLCO2 are all whole numbers. But I want to smooth the plot for aesthetic reasons. Any idea on how to do that?

plot(density(x$PLCO2))

Density Plot

Upvotes: 4

Views: 6766

Answers (2)

Peter
Peter

Reputation: 2400

Alternatively, you can use adjust.

plot(density(x$PLCO2, adjust = 2))

The docs say:

adjust: the bandwidth used is actually adjust*bw. This makes it easy to specify values like ‘half the default’ bandwidth.

Upvotes: 0

Mamoun Benghezal
Mamoun Benghezal

Reputation: 5314

you can make you density plot smoother by increasing the bandwidth (bw)

plot(density(x$PLCO2, bw = bw_bigger))

Upvotes: 4

Related Questions