为什么scale_y_continuous在这里不起作用?没有给出错误信息

2023-12-20

在我的 ggplot (见下文)上,我期待scale_y_continuous(breaks=(seq(0, 90, 10)))将 y 设置在 0 到 90 之间,每隔 10 间隔一次。相反,我没有得到 y 轴或刻度线。

谷歌搜索发现了这个并没有完全解决我的问题:

https://stackoverflow.com/questions/43709180/scale-y-continuous-not-working https://stackoverflow.com/questions/43709180/scale-y-continuous-not-working

using ylim()允许我更改比例,但不允许我将间隔更改为每 10 个。

这是我的数据的 dput:

structure(list(dval = c(73.2, 76.7, 79.2, 74.9, 74.8, 76.8, 74.7, 
74, 77.2, 74.6, 74.2, 72.7), date = structure(c(17646, 17655, 
17675, 17681, 17701, 17729, 17743, 17751, 17757, 17778, 17793, 
17800), class = "Date")), row.names = c(43215L, 43224L, 43244L, 
43250L, 43270L, 43298L, 43312L, 43320L, 43326L, 43347L, 43362L, 
43369L), class = "data.frame")

这是我用来尝试绘制的代码:

ggplot(test, aes(date, dval)) +
    #scale_y_continuous() should be mking Y between 0 and 90 and spaced every 10, but isnt...
    #ylim() works but doesnt set default spacing of 10
    scale_y_continuous(breaks=(seq(0, 90, 10))) +
    #ylim(0, 80) +
    geom_point()+
    geom_smooth(method=lm)

@markus 的评论为我解决了这个问题。添加limits论证scale_y_continuous给了我我想要的输出:

ggplot(test, aes(date, dval)) +
  scale_y_continuous(breaks=(seq(0, 90, 10)), limits = c(0, 90)) +
  geom_point()+
  geom_smooth(method=lm)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

为什么scale_y_continuous在这里不起作用?没有给出错误信息 的相关文章

随机推荐