0

I am having trouble controlling the color of data points in a line chart in R. I have the following code:

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")

This code produces a chart with a blue line and data points filled in red. I would like to have the border color of data points in red as well but I can't figure how to set this pch parameter. I have tried to plot the chart without the type="n" parameter so that I can control the color of the points in the plot function (and not in lines) but when I run the following code

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")

I obtain an empty chart: there is no data points at all. I don't understand what is wrong in my second piece of code and I would like to know if there is another way to control the bordel color of points in a line chart.

Thank you for your help.

david
  • 127
  • 3
  • 9

1 Answers1

0

Example using some made up data:

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

Now draw a line with lines, and then add the points over the top with 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")

enter image description here

thelatemail
  • 91,185
  • 12
  • 128
  • 188
  • I had actually tried this, but it does not work for me: all I get is a blue line with not points. It looks like my R environment does not want to plot just points anymore. – david Nov 29 '13 at 03:43
  • Check your code carefully - you have `Pareto_n` and `Pareto.n` sometimes. It definitely works as you can see. – thelatemail Nov 29 '13 at 03:44