rplotplotrixrescale

Change size of points in R using plot() with multiple added points()


The data is available here.

I am trying to generate the below plot (proportion of individuals~year), with the exception that I need to scale all the points (resF, resM, immF, and immM) to the number of observations for each column (resFN, resMN, immFN, and immMN). enter image description here

The code I use to make the above plot is below:

library (plotrix)

plot(resF~year,data=data, type="b", col="black", xlab="Settlement year", ylab="Number of individuals", bty="l", pch=17, ylim=c(0,1))
ablineclip(v=1993, col="grey95", lwd=14, y1=0)
ablineclip(v=1998, col="grey95", lwd=14, y1=0)
ablineclip(v=2005, col="grey95", lwd=14, y1=0)
ablineclip(v=2010, col="grey95", lwd=14, y1=0)
ablineclip(v=2014, col="grey95", lwd=14, y1=0)
points(resF~year,data=data, col="black", type="b", pch=17)
points(resM~year,data=data, col="grey", type="b", pch=16)
points(immF~year,data=data, col="red", type="b", pch=17)
points(immM~year,data=data, col="orange", type="b", pch=16)
legend("topright", c("Resident females","Resident males", "Immigrant females", "Immigrant males"), col=c("black", "grey","red", "orange"), pch=c(17, 16, 17, 16), box.lty=0)

I am plotting the resF, and adding points for resM, immF, and immM. I want to scale the points according to the number of observations for each column. For example, resF would need to be rescaled according to the number of observations in column resFN, resM scaled to number in resMN, etc.

Based on what I have read, I should be able to rescale the points by adding symbols(x=data$resFN, y=data$year, circles=sqrt(data$resFN/pi), inches=1/3, ann=F, bg="steelblue2", fg=NULL) to my plot() code. I am encountering problems since I am adding multiple points() to the original plot() and I am also rescaling according to values in different columns.

Any suggestions for how I can accomplish this?


Solution

  • For instance, I wouldn't necessarily recommend this particular scaling, but this gives you basic idea. I would just scale the points however you deem appropriate. In particular, you need to decide if they should be scaled separately by category, or scaled by the same amount across all categories.

    plot(resF~year,data=data, type="b", col="black", xlab="Settlement year", 
         ylab="Number of individuals", bty="l", pch=17, ylim=c(0,1))
    ablineclip(v=1993, col="grey95", lwd=14, y1=0)
    ablineclip(v=1998, col="grey95", lwd=14, y1=0)
    ablineclip(v=2005, col="grey95", lwd=14, y1=0)
    ablineclip(v=2010, col="grey95", lwd=14, y1=0)
    ablineclip(v=2014, col="grey95", lwd=14, y1=0)
    points(resF~year,data=data, col="black", type="b", pch=17,cex = resFN / median(resFN))
    points(resM~year,data=data, col="grey", type="b", pch=16,cex = resMN / median(resMN))
    points(immF~year,data=data, col="red", type="b", pch=17,cex = immFN / median(immFN))
    points(immM~year,data=data, col="orange", type="b", pch=16,cex = immMN / median(immMN))
    legend("topright", c("Resident females","Resident males", "Immigrant females", "Immigrant males"), 
           col=c("black", "grey","red", "orange"), pch=c(17, 16, 17, 16), box.lty=0)
    

    enter image description here