8/30/2023 0 Comments Ggplot annotate textThis should become clearer as we create the annotation sections of the plots. The real column names of this data frame won’t appear on my plot, but the data in the rows themselves will. ![]() I’ll also paste the low and high confidence intervals for my hazard ratio estimates together with a hyphen, and call this variable estimate_lab.įinally, I’ll bind a row of data that shows what I want the column names of my annotations to read as (e.g. Model, Hazard Ratio). In other words, we will turn a p-value that reads 0.2 into 0.20, which has four characters (three numbers and a decimal point). I’ll round the numbers to two decimal places (except for p-values that are < 0.01), and then “pad” the numbers as strings so that they take up 4 characters. For this figure, I need two decimal places. We’ll start by rounding our estimates to the significant figures the journal requires. To plot the hazard ratio estimates, we first need to modify the data set a bit. We’ll save this ggplot object as p_mid and move on to the next section of the figure. We first want the models to show in alphabetical order from the top to the bottom of the graph. ![]() Let’s look at how we can plot the log hazard ratio estimates. For this graph, the journal editor told me that it was “journal standard to plot relative measures (ratio data), such as ORs, on log scales to preserve the correct spatial relationship between values.” So, I’m going to be visually showing the log hazard ratio, and annotating later with the hazard ratio. In my experience, journal editors sometimes ask for these estimates to look a certain way during the revision process. This section uses points and lines to indicate the estimate and 95% confidence interval around the estimate. ![]() We will first work on making the standard “forest plot”, or the middle section of the figure. It's certainly possible to write a wrapper but the way units and justification are defined makes it rather verbose, library(ggplot2) Also, to copy to other plots, you won't need to manually calculate values, just change the names of the x and y variables. ![]() The code below is a bit lengthy, but will still place labels correctly if the values in your plot change. However, if you want more control over the position of your labels (for example, if you want them centered, or if you want more space between the axis line and annotation), you can use some math with min() and max() of your plot titles to create centered titles at top, bottom, right, or left. The solution using infinity is good and is definitely the easiest option.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |