2

I'd like to use ggplot2 density geometry using a log transformation for the x scale:

qplot(rating, data=movies, geom="density", log="x")

This, however, produces a chart with probabilities larger than 1. One solution that seems to work is to scale the dataset before calling qplot:

qplot(rating, data=transform(movies, rating=log(rating))

But then the x axis doesn't look nice. What is the correct way to handle this?


It seems that my question doesn't not, in fact, make sense. It seems that it is OK that probability densities are larger than one, as per [2]. What is important is that the integral over the entire space is equal to one [3].

1 Answer 1

3

This gives the right answer.

qplot(rating, y = ..scaled.., data=movies, geom="density", log="x")

stat_density produces new values, one of them is ..scaled.. which is the density scaled from 0 to 1. example plot

HTH

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.