如何用两种颜色填充绘图上的单个“pch"点? [英] How to fill a single 'pch' point on the plot with two-colours?

查看:49
本文介绍了如何用两种颜色填充绘图上的单个“pch"点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果你拿下面的代码,你怎么能改变第三个钻石的填充,所以它会是半黑半白?该解决方案应适用于任何颜色.

If you take the code below, how can you change the filling of the third diamond, so it will be half-black, half-white? The solution should apply with any colors.

data <- c(1,2,3)
plot(data, pch=c(23,18,23), cex=c(2.5,3,2.5))

推荐答案

pch 字符是实际的字体符号,因此您将受到字体中可用内容的限制.另一种选择是使用原始绘图命令来制作您自己的符号".这是非常灵活的,尽管在混合这两种方法时可能会出现调整大小等问题.这个方法是在很好的 my.symbols() 例子中实现的:

The pch characters are actual font symbols, so you will be limited to what is available in your fonts. Another alternative is to use the primitive plotting commands to make your own "symbols". This is very flexible, although there can be issues with resizing, etc., when mixing the two methods. This method is implemented in the nice my.symbols() example:

require(TeachingDemos)

bwDiamond <- function() {
    plot.new()
    polygon(c(0, 0.5, 1, 0.5, 0), c(0.5, 0, 0.5, 1, 0.5), lty=1)
    polygon(c(0.25, 0.5, 1, 0.75, 0.25), c(0.25, 0, 0.5, 0.75, 0.25), col=1)
}

data <- c(1,2,3)

dev.new(width=4, height=4)
plot(data, type='n')
points(data[1:2], pch=c(23,18), cex=c(2.5,3))
my.symbols(data[3], data[3], symb=bwDiamond, symb.plots=TRUE, inches=0.22)

另见此问答:R 中的点符号

这篇关于如何用两种颜色填充绘图上的单个“pch"点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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