在我的 ggplot 上(见下文),我希望scale_y_continuous(breaks=(seq(0, 90, 10)))将 y 设置在 0 到 90 之间,并且每隔 10 间隔一次。相反,我没有得到 y 轴或刻度线。
谷歌搜索发现了这个并没有完全解决我的问题:
usingylim()允许我改变比例,但不允许我将间隔更改为每 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")
Run Code Online (Sandbox Code Playgroud)
这是我用来尝试和绘制的代码:
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)
Run Code Online (Sandbox Code Playgroud)
Mar*_*ark 10
@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)
Run Code Online (Sandbox Code Playgroud)
您的 dval 值仅位于 72 和 79.x 之间,因此您的中断超出了使用的数据范围。
scale_y_continuous(breaks=(seq(72,79,1)))
Run Code Online (Sandbox Code Playgroud)
作品。
| 归档时间: |
|
| 查看次数: |
12715 次 |
| 最近记录: |