0

我无法控制 R 中折线图中数据点的颜色。我有以下代码:

Pareto <- read.table("ParetoFront.csv",header=TRUE,sep=";")
dfP <- data.frame(Pareto$n,Pareto$z)

plot(dfP$Pareto_n,dfP$Pareto_z,xlim=c(1,max(dfP$Pareto.n)),
  ylim=c(min(dfP$Pareto.z),max(dfP$Pareto.z)),xlab="n",ylab="z(n)",type="n")

lines(dfP$Pareto.n,dfPPareto.z,type="o",lwd=2,col="blue",pch=23,bg="red")

此代码生成一个带有蓝色线条和红色填充数据点的图表。我也想将数据点的边框颜色设为红色,但我不知道如何设置此 pch 参数。我试图在没有type="n"参数的情况下绘制图表,以便我可以控制plot函数(而不是lines)中点的颜色但是当我运行以下代码时

Pareto <- read.table("ParetoFront.csv",header=TRUE,sep=";")
dfP <- data.frame(Pareto$n,Pareto$z)

plot(dfP$Pareto_n,dfP$Pareto_z,xlim=c(1,max(dfP$Pareto.n)),
  ylim=c(min(dfP$Pareto.z),max(dfP$Pareto.z)),xlab="n",ylab="z(n)",
  pch=23,col="red",bg="red")

我得到一个空图表:根本没有数据点。我不明白我的第二段代码有什么问题,我想知道是否有另一种方法来控制折线图中点的 bordel 颜色。

感谢您的帮助。

4

1 回答 1

0

使用一些虚构数据的示例:

dfP <- data.frame(Pareto_n=1:10,Pareto_z=1:10)

现在用 画一条线lines,然后用 将点添加到顶部points

plot(dfP$Pareto_n,dfP$Pareto_z,xlim=c(1,max(dfP$Pareto_n)),
  ylim=c(min(dfP$Pareto_z),max(dfP$Pareto_z)),xlab="n",ylab="z(n)",type="n")

lines(dfP$Pareto_n,dfP$Pareto_z,lwd=2,col="blue")
points(dfP$Pareto_n,dfP$Pareto_z,lwd=2,pch=23,col="red",bg="red")

在此处输入图像描述

于 2013-11-29T03:24:28.963 回答