Get rid of gray line in R density plot density at y = 0

烂漫一生 提交于 2019-12-02 12:16:22

问题


I have a density plot that I want to save in an eps file.

My density plot is something like

setEPS()
postscript("myfile.eps")
plot(density(rnorm(1000)))
dev.off()

just with my data and a little bit more complex (changing labels and margins, more lines on top of it, etc).

My problem is that I get an annoying, horizontal thin gray line on top of my density plot at y = 0, and I'd like to get rid of it.

When plotting directly to the X device I don't get this horizontal gray line, but in postscript I always do.

I've tried using dev.copy2eps and also cairo_ps() instead of postscript(), but I still get the grey line.

I've also tried using different (and random) data, with a very simple plot like the code block above, and still get the grey line in the postscript.

Does anyone know how to get rid of this line?


回答1:


Read the help page:

?plot.density

zero.line.......logical; if TRUE, add a base line at y = 0

I will admit that I didn't discover this by reading the help page. I had looked at the code for density.default, found nothing useful, then tried plot.density, got the nothing, found message, and then tried:

> getAnywhere(plot.density)

Which produced this ... making me realize that I should have started with the help page:

A single object matching ‘plot.density’ was found
It was found in the following places
  registered S3 method for plot from namespace stats
  namespace:stats
with value

function (x, main = NULL, xlab = NULL, ylab = "Density", type = "l", 
    zero.line = TRUE, ...) 


来源:https://stackoverflow.com/questions/30145824/get-rid-of-gray-line-in-r-density-plot-density-at-y-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!