简体   繁体   English

使用带有 log y 轴的 geom_ridgeline

[英]Using geom_ridgeline with a log y-axis

I am trying to visualise timeseries data, and thought the ggridges package would be useful for this.我正在尝试可视化时间序列数据,并认为 ggridges 包对此很有用。 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.我尝试使用 y = 0.001 而不是 0,因为 y = 0 失败,但是高度不正确。 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))

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使用ggridges的示例( https://wilkelab.org/ggridges/articles/introduction.html ),我添加了+1以避免在获取log10时出现零(以及Inf

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:产生:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM