符不scale_y_continuous()在GGPLOT2(breaks without scal

2019-08-17 17:22发布

我正在寻找设置在一个情节断裂,而无需使用scale_y _...(场所= C(X1,X2))功能的方法。 问题是:我想要一些箱线图。

    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

谢谢您的帮助!

Answer 1:

您可以结合coord_cartesian()scale_y_continuous()中的一个情节,只是删除limits=c(-1,1)从规模经济的功能。 当您使用limits=尺度函数里面,数据子集在和谐。 coord_cartesian()只缩放值的那个区域。

 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))


文章来源: breaks without scale_y_continuous() in ggplot2
标签: r ggplot2