r - label column with count fill value in ggplot2 -
I would like to label each column with that count of fill_factor for that specific column, but I can not find more than one Label per column.
mydata.df & lt; - data.frame (Fill_factor = c ("Fill1", "Fill3", "Fill1", "FILL2", "Fill1", "Fill1", "ABA", "AA", "CA", "BB" "AA", "B.B.", "F", "FILL2", "FILL2", "FILL3"), Calculation = C ("AA", "CC")) Q & lt; - qplot (calculation, Data = mydata.df, fill = Fill_factor, geom = "bar", position = "fill") # gene name q # theme (axis.text.x = element_text (angle = -90, hjust = 1), text = element_text (Size = 10)) fill in the table (mydata.df $ calculation, mydata.df $ Fill_factor) 1 FILL2 Fill3 FILL3AA 2 2 0 0 BB 1 1 1 CC 1 0 0 1 I have also used the function DDPA but I do not know how to get the correct position
mydata.df count & lt; - Ddply (mydata.df, (Fill_factor, Count), nrow) colnames (mydata.df.count) & lt; -c ("Fill_factor", "Count", "Frequency") mydata.df.count & lt; - DDPA (mydata.df.count (count), transform, pos = cumsum (frequency) / 5) # wrong position p = ggplot (mydata.df.count, aes (x = calculation, y = frequency), stat = "identity ") + Geom_bar (AES (fill = fill_factor, position =" fill ") + geom_text (AES (label = frequency, y = pos), size = 5) p how do i Can I move the text labels in position = "correct" position (multiple text per column) using the "filling" argument? And how can I sort the calculation levels to order for the most fill factor == "Fill 1"?
You must associate the cumulative frequency with the total frequency and then the vertical label be adjusted.
Code:
mydata.df.count & lt; - ddply (mydata.df.count; (calculation), transform, position = Cumsum (frequency) / zodiac (frequency) ggplot (mydata.df count, aes (x = count, y = frequency, fill = fill_factor)) + Geom_bar (stat = "identity", position = "fill") + Geom_text (aes (y = pos, label = frequency), vjust = 3) Result:
Comments
Post a Comment