Tuesday 15 January 2013

r - Annotating individual facets in ggplot2 -


My apologies if this is a duplicate I have read many posts about the interpretation of individual aspects I my problem is the closest appears But I do not want to be with my data like this, I want to add minimal short font labels to minimum and confidence interval in each side. Any hard work in the right direction would be most appreciated, I'm just rolling with ggplot Thanks a lot.

  Library (ggplot2) library (grid extras) results & lt; -c (1,1,1,2,2,3,3,3) or & lt; -c (1.97,2.47, 3.56,1.73,2.25,4.0 9,1.21,1.48,2.25) minute & lt; -c (1.37,1.74,2.55,1.13,1.52,2.84,0.74,0.95,1.4 9) Maximum & lt; -c (2.83,3.494.98,2.66, 3.35.5.9 1.97,2.33,3.41) Aces and LT; -C (1,2,3,1,2,3,1,2,3) AC & lt; -Data Frame (CBIDand (results, or, minimum, maximum, ACS) AC2 and LT; - Data frame (minimum, maximum, result, aces) AC_lables & lt; - list ('1' = "1 ACE", ' 2 '= "2EE",' 3 '= "3 ACE") Ace_labeller & lt; -function (variable, value) {return (ace_labels [value])} Ace $ Output = Factor (Ace Dollar result, level = c ( "3", "2", "1"), labels = c ( "MH Barrier to Work: model 3", "MH Barrier to Work: model 2", "Depression: model 1")) p & lt; -ggplot (data = ac, aes (x = or, y = outcum, label = geom_point (aes = 8)) + geom_text (size = 5, vj = 1.75) + geom_errorbarh (AES (xmin = min, xmax = max), height = 1) + geom_vline (xintercept = 1, linetype = "dashed") + scale_x_log10 ( Brakes = Sik (1,6,1), name = "odds ratio (ORS) and 95% confidence interval") + Laboratories (y = "") + facet_grid (Equus ~, Labeller = AC_labeler) + Guide (size) = Crop) + theme_bau () + theme (axis .text.y = element_text (size = 12)) + theme (strip.text.y = element_text (size = 12)) + theme (axis.title.x = element_text ( Size = 12, hjust = .5)) #I can get one over there, but I can not figure out how to Packet P + is controlling Anootet ( "Text" label = "1.37", x = 1.37, y = 2.8, size = 4). I get the Data Frame Approach # (which is not exactly at all) AC 2 & lt; -data.frame (cbind (min, result, aces)) P + geom_text (Data = AC2, AES (X = minutes, Y = 2.8, label = minutes, inherit.aes = FALSE)) + facet_grid (Aces ~. )  

this will add the minimum and maximum values ​​of the interval confidence labels: < / Geo_text (AES (label = max, x = max), vjust = 1.5, size = 4)

this works because the g Gplot already Avs in your original data frame Required all assume that you've got. You just need to tell geom_text that you want to use the minimum and max values ​​as both text labels and x-axis locations Are there. ggplot takes care of the rest (ie, y- value factor space), because they are already an intrinsic part of the plot, as long as you do not override them.


No comments:

Post a Comment