Error bars not at top of graph r7/21/2023 Xlab=substitute(paste("Intra-Acb amphetamine (",mu,"g)")), # substitute() with an empty environment seems necessaryĪsp=0.5 # aspect ratio: here, one x unit is as long as 0.5 y unitsĪxis(side=1, at=1:4, labels=dose) # turn on X axisĪxis(side=2, las=1) # turn on Y axis (with text horizontal)īox(bty="L") # bty=box type to surround plot (e.g. Yaxs="i", # makes the axis just fit the range, rather than extending 4% beyond # spaced categories (at absolute x positions 1,2,3,4), and then force the labels on # in what follows, we force the four doses (0, 3, 10, 20) to be displayed as equally )Īrrows(x, y + ebu, x, y - ebl, angle = 90, code = 3, Superpose.eb <- function (x, y, ebl, ebu = ebl, length = 0.08. # now we define a new function for adding error bars: "D:/Documents/Techniques/R/PhD_fig21A.csv", Here we introduce a few more fancy things, including expressions and Greek symbols in the axis labels, a categorical X axis, and a free-floating error bar. That produces the following in the R graphics window: Lty=c(1,1,3) # sequence of line types for the legendĭetach(fig37b) # for good form, detach it again after use. Pt.bg=c("white","black",NULL), # sequence of fill colours for the points Pch=c(24,21,-1), # sequence of point types for the legend -1 is a nonexistent point Legend=c("sham","ACCX","chance"), # sequence of text for the legend Y=8.5, # y coordinate of the top left of the legendīox.lty=0, # line type to surround the legend box (0 for none) X=0.5, # x coordinate of the top left of the legend Las=1, # axis labels horizontal (default is 0 for always parallel to axis)įont.lab=2 # 1 plain, 2 bold, 3 italic, 4 bold italic, 5 symbolĪdd=TRUE # ADD this plot to the previous oneĪbline(h=0, lty=3) # horizontal line at y=0, linetype 3 = dotted Main="Two-stimulus discriminated approach task", Xaxp=c(1,12,11), # x-min tick mark, x-max tick mark, number of intervals between tick marks Sfrac=0.005, # width of error bar as proportion of x plotting region (default 0.01) Gap=0, # distance from symbol to error bar Type="o", # p=points, l=lines, b=both, o=overplotted points/lines, etc. Pch=24, # symbol (plotting character) type: see help(pch) 24 = filled triangle pointing up Uiw=SEM_sham, # error bar length (default is to put this much above and below point) Header=TRUE, sep=",", na.strings="NA", dec=".", strip.white=TRUEĪttach(fig37b) # this is perhaps not the most elegant method: it puts the contents of "fig37b" on the search path "D:/Documents/Techniques/R/PhD_fig37B.csv", The code is commented using # characters for explanation. The code below imports the data, ensures the gplots library is available, and then uses a plotCI call to create the basic graph and the first line with its error bars, another plotCI call to add the second line and error bars, an abline call to add an absolute-referenced line, and a legend. You may also need to edit the code below so that the filename points to wherever you have stored the PhD_fig37B.csv file above. You need to install the gplots packages from the R menus if you haven't done so before (Packages > Install Packages > choose a CRAN mirror > select "gplots"). We'll look at one here based on the plotCI function, part of the gplots package. There are a number of ways to achieve this. Note also that the code is longer than it needs to be, because it is spaced and commented for clarity. In all the code that follows, you'll have to change the path names to reflect where you actually put these files. These files are all comma-separated value (CSV) text files:
0 Comments
Leave a Reply. |