Created
April 8, 2013 12:28
-
-
Save rmaia/5336427 to your computer and use it in GitHub Desktop.
Adding the sample name to the end of the plotted spectra
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
data(sicalis) | |
# plot the desired spectra, leaving room horizontally to add labels | |
plot(sicalis, select=2:4, xlim=c(300,800)) | |
# find the y position to add the labels right where they finish (wavelength=700) | |
# using nrow to select the last row (for the last wavelength value) | |
# subset the last wavelength value (column 1) | |
xpos <- sicalis[nrow(sicalis), 1] | |
xpos | |
# subset the last reflectance value for the spectra I want to label | |
ypos <- sicalis[nrow(sicalis), 2:4] | |
ypos | |
# add the labels | |
# pos=4 will put the text to the right of the specified coordinate | |
# | |
# IMPORTANT: the actual relative size of the text will depend on your resolution and how | |
# you're exporting, so you might need to tweak the text() command a bit | |
labels <- c('crown', 'throat', 'belly') | |
text(xpos, ypos, labels, pos=4) | |
## | |
# if you want to make it "prettier" | |
## | |
plot(sicalis, select=2:4, | |
xlim=c(300,750), col=spec2rgb(sicalis), xaxt='n') | |
axis(1, at=seq(300, 700, by=100)) | |
text(xpos, ypos, labels, pos=4) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment