如何在 R 中创建带有自定义点的图? [英] how to create a plot with customized points in R?

查看:33
本文介绍了如何在 R 中创建带有自定义点的图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以使用 plot 命令中的 type = "o" 参数创建一个带有线和点的图.我想对此进行更多控制——我希望能够将o"绘制为完整点,带有我选择的黑色边框和填充颜色、自定义大小和与线不同的颜色.线条也一样,我想让它更粗,以及我选择的颜色.我将如何继续这样做?

I know I can create a plot with line and dots using the type = "o" argument in the plot command. I would like some more control over this -- I want to be able to draw the "o" as full dots, with black border and fill-in color of my choice, of customized size and of a different color than the line. Same for the line, I want to make it thicker, and of my choice of color. How would I go on about doing that?

直到现在我发现的只是一个普通的

What I found until now is just a plain

 plot(y, type= "o")

这对于我的需求来说太差了.

which is too poor for my needs.

我对使用 ggplot 不感兴趣,而是使用 R 的内部绘图库.任何帮助表示赞赏.

I am not interested in using ggplot, but instead use the internal plot library of R. Any help appreciated.

推荐答案

你可以使用分层(作为一名社会研究人员,我不再在 base 工作太多了,我喜欢 ggplot 的 facet_grid,所以可能会有更好的方式)如:

You could use layering (I don't work in base too much any more as a social researcher I love the facet_grid of ggplot, so there may be a better way) as in:

x <- sort(rnorm(25))
y <- sort(rnorm(25))
z <- as.factor(sample(LETTERS[1:5], 25, r=TRUE))

plot(x, y, pch = 19, cex = 1.3)
par(new = TRUE)
plot(x, y, pch = 19, cex = 1, col = z)

这给了你:

这篇关于如何在 R 中创建带有自定义点的图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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