我正在嘗試通過 ggplot2 注釋 R 中的矩形,以獲得對數刻度的圖形。這是我要添加的注釋層:
annotate("rect",xmin=293.3, xmax=312, ymin=-Inf, ymax=Inf, fill='gray')
當然,我理解負無窮大會導致問題,因為它是一個對數刻度并且沒有負值。由于我預先指定了 y 尺度的限制,有人對如何使用這種方法或其他方法創建“負無窮大”到無窮大矩形有任何想法嗎?
uj5u.com熱心網友回復:
R 給出log(0)as -Inf,因此您可以在登錄時使用ymin = 0來生成-Inf。
內置資料演示:
ggplot(mtcars, aes(x = wt, y = mpg))
annotate("rect", xmin = 2, xmax = 4, ymin = 0, ymax = Inf, fill = 'gray')
geom_point()
scale_y_continuous(trans = "log")

轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/384676.html
