当 pch=21 时,图例框和整个图框之间的点边框颜色和线条颜色不同 [英] points border color and line color is different between legend box and whole plot box when pch=21

查看:133
本文介绍了当 pch=21 时,图例框和整个图框之间的点边框颜色和线条颜色不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

环境

MACOSX 10.9.4R 3.3.1

MACOSX 10.9.4 R 3.3.1

我的问题

图例中点的边框颜色为绿色4.但是整个图的点的边框颜色是黑色的.见上图,绘图框中有三个点,线条颜色为绿色4,点边框为黑色,点背景为红色.但是,在右上角的图例框中,线条颜色为green4,点背景为红色,点边框颜色 不是黑色,与线条相同的是green4在图例框中.

The border color of point in legend is green4. But the border color of points for whole plot is black. See the figure above, in the plot box there are three points and line color is green4, the point border is black and the points background is red. However, in the legend box which is on topright the line color is green4, the point background is red, the point border color is not black which is green4 same with the line in legend box.

如果在图例中添加col,图例框的点边框颜色会发生变化,同时图例框的线条颜色也会发生变化.

If you add col in legend, the point border color in legend box is changed and at the same time the line color in legend box is changed either.

我当前的代码如下:

initial.dir<-getwd()
setwd("/works/bin")
sink("r.o")
pk <- read.table("2017.info")
rownames(pk)<-c("k","pk")
d.f <- data.frame(t(pk))

pdf(file="5000-max.pdf")

plot(
  d.f$k,
  d.f$pk,
  type = "n",
  log = "xy",
  main = "Degree distribution",
  xlab = "k",
  ylab = "p(k)",
  xlim = c( 10^0, 10^2),
  ylim = c( 0.00001, 1),
  xaxt="n", yaxt="n",
  xaxs="i", yaxs="i",
)

lines( d.f$k, d.f$pk, col = "green4", lty = "solid")
points( d.f$k, d.f$pk, bg = "red", pch = 21 )
legend("topright", inset=.05, c("p(k)"), lty="solid", pch=21, col=c("green4"), pt.bg="red")

axis(side = 1, at = 10^(0:2), labels = expression(10^0, 10^1, 10^2))
axis(side = 2, at = 10^(-5:0), labels = expression(10^-5, 10^-4, 10^-3, 10^-2, 10^-1, 10^0))

abline(h=outer((1:10),(10^(-5:-1))), col="#00000033", lty=2)
abline(v=outer((1:10),(10^(0:1))), col="#00000033", lty=2)

box()
dev.off

sink()
setwd(initial.dir)

我期望的是

绘图中的线条颜色、点边框颜色、点背景颜色应与图例相同.

The line color, points border color, points background color in the plot should be same with the legend.

我应该如何更改我的代码?谢谢.

How should I changed my code? Thanks.

推荐答案

为了改变图表中点边框的颜色,我会改变

In order to change the color of point borders in the chart, I would change

points( d.f$k, d.f$pk, bg = "red", pch = 21 )

points( d.f$k, d.f$pk, bg = "red", col = "green4",pch = 21 )

要更改图例中的颜色,只需更改

To change the color in the legend just change

legend("topright", inset=.05, c("p(k)"), lty="solid", pch=21, col=c("green4"), pt.bg="red")

legend("topright", inset=.05, c("p(k)"), lty="solid", pch=21, col=c"black", pt.bg="red")

这篇关于当 pch=21 时,图例框和整个图框之间的点边框颜色和线条颜色不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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