在ggplot2中没有scale_y_continuous() [英] breaks without scale_y_continuous() in ggplot2

查看:2052
本文介绍了在ggplot2中没有scale_y_continuous()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种不使用scale_y _...(breaks = c(x1,x2))函数来设置图表中断点的方法。问题如下:我想要一些盒子图。

I was searching for a method to set breaks in a plot without using the scale_y_...(breaks=c(x1,x2)) function. The problem is the following: I want some boxplots.

    require(ggplot2)
    a <- rnorm(10, 0, 5)
    a <- as.data.frame(a); colnames(a) <- "test"

    ### original boxplot
    ggplot(data=a, mapping=aes(y=test, x=rep(1,10))) +
      geom_boxplot()

    ### scale_y_continous() cuts of my data points and changes the boxplot!
    ggplot(data=a, mapping=aes(y=test, x=rep(1,10))) +
      geom_boxplot() +
      scale_y_continuous(limits=c(-1,1), breaks=c(-1,0,1))

    ### I am therefore using coord_cartesian() but I am missing a breaks() function
    ggplot(data=a, mapping=aes(y=test, x=rep(1,10))) +
      geom_boxplot() +
      coord_cartesian(ylim = c(-1,1)) # +
    # breaks(c(-1,0,1))   # something like this

谢谢您的帮助!

推荐答案

您可以将 coord_cartesian() scale_y_continuous()在一个plot中,只需从scale函数中移除 limits = c(-1,1)即可。当您在缩放函数中使用 limits = 时,数据会在该diapason中进行子集化。 coord_cartesian()只是放大该区域的值。

You can combine coord_cartesian() and scale_y_continuous() in one plot, just remove limits=c(-1,1) from scale function. When you use limits= inside the scale function, data are subsetted in that diapason. coord_cartesian() just zooms that region of values.

 ggplot(data=a, mapping=aes(y=test, x=rep(1,10))) +
      geom_boxplot() +
      coord_cartesian(ylim = c(-1,1))+
      scale_y_continuous(breaks=c(-1,0,1))

这篇关于在ggplot2中没有scale_y_continuous()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆