仅在R图中显示轴的一部分

时间:2017-03-30 22:31:09

标签: r plot

背景:如下图所示,目前y轴从-2延伸到2(即y轴包含正值和负值)。

问题:

保持如下图所示的所有内容,我想知道是否可能有一种方法仅显示y轴的正面部分(从0开始)并以某种方式隐藏y轴的负部分? (请参阅下面的R代码

enter image description here

以下是R代码:

if(!require(library(plotrix))){install.packages('plotrix') }
library(plotrix)          ## A package for drawing ellipses ##


plot(1, ty='n', ann = F, axes = F, xlim = c(-4, 6), ylim = c(-2.5, 2) ) ## platform for ellipses

axis(side = 2)   ## HERE is my question ## ???


draw.ellipse(x = rep(1, 11), y = rep(-1.2, 11), 
     a = seq(1, 6, by = .4), b = seq(1/4.5, 6/4.5 , by = .4/4.5 ), 
     lty = 2, border = 'gray60' )       ## Draw multiple Concentric ellipses ##


AA <- seq(-4, 6, len = 13)     ## A range of values on the x-xis just like "xlim" ##
BB <- dcauchy( AA, 1, .95)*5   ## The Height for the AA according to a distribution ##

segments(AA, rep(-1.2, length(AA) ), AA, BB, lty = 3, lwd = 2, col= 'green4' )

curve(dcauchy(x, 1, .95)*5, -4, 6, add = T, col ='magenta', lwd = 3)

1 个答案:

答案 0 :(得分:1)

请参阅?axis。您只需要指定at参数。

axis(side = 2, at = 0:2)