Created
March 24, 2016 12:47
-
-
Save ifitzpat/6cf6a5cff2f4e526fbff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#function adapted from http://mpastell.com/2009/09/11/matlab-style-stem-plot-with-r/ | |
stem = function(x,y,slope,intercept,pch=16,linecol=2,clinecol=1,lty=2,from_mean=FALSE,...){ | |
if (missing(y)){ | |
y = x | |
x = 1:length(x) | |
} | |
#this plots the points | |
plot(x,y,pch=pch,...) | |
#this plots the line | |
abline(intercept,slope) | |
if (from_mean) { | |
#plot the mean line | |
abline(mean(y),0,lty=1,col=1) | |
#this plots the stem lines to the mean line | |
for (i in 1:length(x)){ | |
lines(c(x[i],x[i]), c(mean(y),slope*x[i]+intercept),col=linecol,lty=lty) | |
} | |
} | |
else { | |
#this plots the stem lines to each point | |
for (i in 1:length(x)){ | |
lines(c(x[i],x[i]), c(y[i],slope*x[i]+intercept),col=linecol,lty=lty) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment