R 为什么scale_y_连续不在这里工作?没有给出错误消息
在我的ggplot(见下文)中,我希望R 为什么scale_y_连续不在这里工作?没有给出错误消息,r,ggplot2,R,Ggplot2,在我的ggplot(见下文)中,我希望缩放y_连续(中断=(seq(0,90,10))将y设置在0和90之间,并每隔10间隔一次。相反,我没有y轴或记号 谷歌搜索结果显示,这与我的问题并不完全相符: 使用ylim() 这是我的数据的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
缩放y_连续(中断=(seq(0,90,10))
将y设置在0和90之间,并每隔10间隔一次。相反,我没有y轴或记号
谷歌搜索结果显示,这与我的问题并不完全相符:
使用ylim()
这是我的数据的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)
您的dval值仅在72和79.x之间,因此您的中断超出了使用的数据范围
scale_y_continuous(breaks=(seq(72,79,1)))
有效。来自@markus的评论为我整理了这个。将limits
参数添加到scale\u y\u continuous
得到了我想要的输出:
ggplot(test, aes(date, dval)) +
scale_y_continuous(breaks=(seq(0, 90, 10)), limits = c(0, 90)) +
geom_point()+
geom_smooth(method=lm)
您是否也尝试过调整scale\u y\u continuous
的limits
参数?也就是说,limits=c(0,90)
谢谢马库斯。这很有效,结果完全符合我的要求。我不能接受你的评论作为回答,别担心。当Erich编辑它时,接受它的答案。它将是…+连续缩放(极限=c(0,90),中断=(顺序(0,90,10))+…