【发布时间】:2018-11-13 21:21:27
【问题描述】:
考虑以下数据/图,因为我只将数值分配给pch。
plot(1:20, col='blue', pch=20);
points(2:22, col='red', pch='+', cex=2)
points(4:24, col='green', pch=15)
legend('bottomright',c('Blue','Red', 'Green'),
col=c("blue", "red", "green"), horiz=T, cex=0.8,
pch=c(20,20,15), bg='white')
但是当我包含一个字符值时,它仍然会绘制一个图例,但使用了错误的点类型。
legend('bottom',c('Blue','Red', 'Green'),
col=c("blue", "red", "green"), horiz=F, cex=0.8,
pch=c(20,'+',20), bg='white')
而当只使用字符值时,图例又是正确的:
legend('bottomleft',c('Blue','Red', 'Green'),
col=c("blue", "red", "green"), horiz=F, cex=0.8,
pch=c('!','+','*'), bg='white')
中间的图例是问题所在。 如何使用正确的点类型绘制图例?
【问题讨论】:
-
因为您将向量传递给
pch,并且向量必须是相同的数据类型 -
如果我使用
pch=c('20','+','20'),它也会抛出警告并且没有正确绘制它,尽管向量现在只包含字符。 -
您需要查看
?points以找到“+”的等值数字 - 请参阅下面的答案 -
您需要
plot(1, type="n", xlab="", ylab="", ylim = c(1,12), xlim=c(1,12)); text(1:12, rep("!", 12))之类的东西吗? -
不,我正在寻找一种在图例中混合字符和点类型的方法。但是克里斯的回答已经解决了。谢谢!