![]() ![]() Labels are parallel (=0) or perpendicular(=2) to axis (i.e., the value on the other axis where it crosses) The coordinate at which the axis line is to be drawn. )Īn integer indicating the side of the graph to draw the axis (1=bottom, 2=left, 3=top, 4=right)Ī numeric vector indicating where tic marks should be drawnĪ character vector of labels to be placed at the tickmarks You can create custom axes using the axis( ) function.Īxis( side, at=, labels=, pos=, lty=, col=, las=, tck=. See help(plotmath) for details and examples. You can add mathematically formulas to a graph using TEX-like rules. Xlab="Weight", ylab="Mileage", pch=18, col="blue") The x, y, and label vectors should all be the same length. Specify location as a set of x, y coordinates and specify the text to place as a vector of labels. You can use the text( ) function (see above) for labeling point as well as for adding other text annotations. Other common options are cex, col, and font (for size, color, and font style respectively). you can also specify adj=0 for left/bottom alignment or adj=1 for top/right alignment. you can specify line= to indicate the line in the margin starting with 0 and moving out. If you specify pos, you can specify offset= in percent of character width. Alternatively, the text can be placed interactively via mouse by specifying location as locator(1). ![]() ![]() (To practice adding text to plots in R, try this interactive exercise.) text( ) places text within the graph while mtext( ) places text in one of the four margins. Text can be added to graphs using the text( ) and mtext( ) functions. Many other graphical parameters (such as text size, font, rotation, and color) can also be specified in the title( ) function. Xlab=" x-axis label", ylab=" y-axis label") Title(main=" main title", sub=" sub-title", Use the title( ) function to add labels to a plot. Xlim=c( xmin, xmax), ylim=c( ymin, ymax))įor finer control or for modularization, you can use the functions described below. Xlab=" X-axis label", ylab=" y-axix label", Plot( x, y, main=" title", sub=" subtitle", In another post I read the advice to use xaxt="n", but I cannot get that to work with ggplot2.Many high level plotting functions (plot, hist, boxplot, etc.) allow you to include axis and text options (as well as other graphical parameters). I also tried levels=c(1,2,3,4,5) and labels=c("1 hour", "4 hours", etc) butĪll I get is an empty x-axis, no new labels. I searched this site and google and came up with this code: plot1 <- plot + scale_x_discrete(labels=c("1"="1 hour", "2"="4 hours", "3"="8 hours", "4"="POD1 Morning", "5"="POD1 Afternoon")) I would like to replace 1, 2, 3, 4, 5 on the x-axis with the labels 1 hour, 4 hours, 8 hours, POD1 Morning and POD1 Afternoon. With several commands, I adjusted the graph to my liking and I have this: I am quite new to R and I am trying to create a spaghetti plot to compare in 4 groups the percentage of patients taking rescue medication, at different timepoints (1 hour after surgery, 4 hours, 8 hours and post-operative day 1 morning and post-operative day 1 afternoon).Īfter playing around, I created a decent graph, starting from this code: plot <- ggplot(data=rescue, aes(Measurement, Percentage, color=factor(Group))) + geom_line() ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |