0

I am trying to visualise timeseries data, and thought the ggridges package would be useful for this. However some of my data needs to be plotted on a log-scale. Is there a way to do this?

I tried it using y = 0.001 instead of 0, as y = zero fails, but then the heights are not correct. This can be seen when you plot the points as well.

Thanks

Example below:

data <- data.frame(x = 1:5, y = rep(0.001, 5), height = c(0.001, 0.1, 3, 300, 4))
ggplot(data) +
  geom_ridgeline(aes(x, y, height = height),fill = "lightblue") +
  scale_y_log10() +
geom_point(aes(x=x, y=height))
Jenni G
  • 35
  • 1
  • 4

1 Answers1

0

Hopefully this will give you a lead towards solving your problem.

Using an example from ggridges (https://wilkelab.org/ggridges/articles/introduction.html), I added +1 to avoid zeros (and thus Inf) when taking log10

library(ggridges)
d <- data.frame(
  x = rep(1:5, 3),
  y = c(rep(0, 5), rep(1, 5), rep(2, 5)),
  height = c(0, 1, 3, 4, 0, 1, 2, 3, 5, 4, 0, 5, 4, 4, 1)
)

ggplot(d, aes(x, (y + 1), height = height, group = y)) + 
  geom_ridgeline(fill = "lightblue")+
  scale_y_log10() +
  annotation_logticks(sides = "l")

Generates:

enter image description here

jmcastagnetto
  • 441
  • 2
  • 7
  • My data set has values <1, eg 0.001. Therefore I can't add 1 to y, I need to add a smaller value – Jenni G Mar 02 '20 at 23:55
  • 1
    With such small values, taking the log will generate issues with the scaling. Closest thing I can think of, is to use `log1p()` to transform the values, and perhaps play with some scale shifts. – jmcastagnetto Mar 03 '20 at 00:14