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.
Example using some made up data:
Now draw a line with
lines
, and then add the points over the top withpoints
: