# Title: R guide to expressions and axis labels # Date: 2008-02-11 # Project: CFL R Graphics (link) rm(list=ls()) # clear objects graphics.off() # close graphics windows # Create a plotting space par(mar=c(0,0,0,0)) plot(1:10,1:10, type='n',xlab=expression('x'^(2-1)),ylab=expression('y'^gamma)) # Overview: # - embed everything within 'expression()' # - to link pieces of text with mathematical expressions or special functions, # use 'paste()' # - to put parenthesis around part of an equation, use 'group('(',expression,')') # Explanation of expression, paste, group, and list: # # Expression: # expression() is a command that tells R to save the enclosed commands as # something to render instead of something to evaluate. Use it when you # want to express a function or units in type. # # Paste: # paste() is a way of linking together text, variables, and rendered functions # so that they dont overlap on screen. For example, linking together text on # an axis with some expression of units is best done by enclosing them within # a paste command. See examples below. # # Group: # group() is a function that will intelligently create parenthesis around # mathematical equations. Note that it always takes 3 parameters, the first # and last are the opening and closing parentheses respectively, and the # middle is what is rendered between them. # # List: # list() is a simple way of making an ordered list. It renders as the items of # the list separated by commas. text(5,10,expression(paste('Greek letters: ',list(alpha, beta, gamma, Alpha, Beta, Gamma)))) text(5,9,expression(paste('Math expressions: ',x^group('(',gamma-2,')')))) text(5,8,expression(paste('Bold and italics: ',bold(bold),' ', italic(italic),' ', bolditalic(both)))) text(5,7,expression(paste('Super- and subscripts: ', super^group('(',lambda,')'),' ', sub[group('[',lambda,']')]))) text(5,6,expression(paste('Summation: ',sum(x[i], i==1, n)))) text(5,5,expression(paste('Coordinates: ',89 * degree, 42 * minute, 14 * second,'W ',46 * degree, 4 * minute, 41 * second, 'N'))) text(5,4,expression(paste('Integral: ', integral(f(x) * dx,a,b)))) text(5,3,expression(paste('Limit: ', lim(f(x),x %->% 0)))) text(5,2,expression(paste('For additional examples see: demo(plotmath) and help(plotmath)'))) # Further reading and examples: # help(plotmath) # demo(plotmath)