'Plot the log(density) of a theoretical distribution over the log(density) of a empirical vector

If I want to plot the log(density) of a logged vector, I would go:

db %>% ggplot() +
 geom_density(aes(x=log(vector), y=log(..density..)), size = .9) +
 theme_test()

This seems to work.

Now I want super-impose a red line as a theoretical model; I would add:

db %>% ggplot() +
 geom_density(aes(x=log(vector),
                  y=log(..density..)), size = .9) +
 geom_density(aes(x=log(runif(length(vector),0,1)),
                  y=log(..density..)), color = "red", size = .9) +
 theme_test()

But this seems to mess with ..density..; what's the easiest way to trace a theoretical model over an empirical?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source