R ggplot2 stacked bar plot, x as.factor(Time), fill = c(Mean.E, Mean.T, Mean.P) -
I am trying to create a stacked bar plot but there is no luck. Unfortunately I'm unable to understand how I can post datafrom, and I'm a new user so that the images can not be posted. I have given the layout of the data below. I want to plot the tap on the basis of the location, in the form of X Factor (time), as Y, should be added by the group for the bar and every E, T, should be filled with the mean of P, showing the standard error bar. While I plot a single value as a good luck, I am unable to plot as stacked bars. Appreciate the help.
location group time mean e mean t mean pse e se t se p form t 48 0.52 0.02 0.47 0.29 0.07 0.29 form C 48 0.37 0.03 0.61 0.28 0.09 0.28 farm T24 0,59 0 , 01,040, 0, 0, 0, 0, 28, form C4 0,56, 0, 0, 0, 43, 0, 0, 0 0 0, 29, form t, 0, 0, 0, 0, 0, 0, 0, 43 0 , 29 0,04 0,29 Form C 0,5 0,35 0,01 0,64 0,28 0,05 0,28 Priestin T48 0,46 0,03 0,52 0,29 0,10 0 , 29 Princene C48 0,43 0,02 0,55 0,29 0,08 0.29 Priestin T24 0,43 0,02 0,55 0,29 0,08 0,29 Priestin C24 0,26 0, 04 0,71 0,25 0,11 0,26 Pristine T. 0.5 0,52 0,03 0,45 0,29 0,09 0,29 Priestin C 0,5 0,33 0,03 0,65 0,27 0,09 0,28
let Shout:
dput (structure) (list (location = structure (c) (1l, 1l, 1l, 1l, 1l, 1l, 2l, 2 L2L, 2L, 2L, 2L) .Label = C ("Farm", "Prestin"), class = "factor"), group = structure (C (2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L) .Label = C ("C", "T"), class = "factor"), time C = (0.5, 0.3, 0.5, 9, 0.56, 0.56, 0.35, 0.46, C 0.43, 0.43, 0.26, 0.52, 0.33), `Mean T` = C (0.02, 0.03, 0.01, 0.01, 0.01, 0.01, 0.03, 0.02, 0.02, 0.04, 0.03, 0.03),` Mean P` = C ( 0.47, 0.61, 0.4, 0.43, 0.43, 0.64, 0.52, 0.55, 0.55, 0.71, 0.45, 0.65), `SE E` = c (0. 29, 0.28, 0.28, 0.29, 0.29, 0.28, 0.29, 0.29, 0.29, 0.25, 0.2 9, 0.27), `se t` = c (0.07, 0.09, 0.06, 0.05, 0.04, 0.05, 0.1, 0.08, 0.08, 0.11, 0.0 9, 0.09), `sep` = c (0.2 9, 0.28, 0.28), 0.29, 0.2 9, 0.28, 0.2 9, 0.2 9, 0.2 9, 0.26, 0.2 9, 0.28) . Name = C ("Location", "Group", "Time", "Pisce E", "Pisce T", "Pis P", "SEE", "SE T", "SE P"), class = " Data.frame ", line.Name = c (na, -12l)) # Is this an easy way to merge? Library (data.table) dat_m1 & lt; - setDT (melt (DAT [, 1: 6], id = c ('group', 'time', 'location'))) dat_m2 < - setDT (Melt (DAT [, C (1: 3,7: 9)], ID = C ('location', 'time', 'group'))) dat_m1 $ var_group & lt; - sapply (as.character (dat_m1 $ variable), function x) unlisted (strsplit (x, '')) [2]) dat_m2 $ var_group & lt; Setkey (dat_m1, time, location, group, var_group) setkey (dat_m2, time, location, etc.) - sapply (as.character (dat_m2 $ variable), function (x) unlisted (strsplit (x, '')) [2] Group, var_group) dat_m & lt; - Merge (dat_m1, dat_m2, allow.cartesian = TRUE) # Suggestions clarity mydodge & lt option; - Position_dodge (width = 0.8) ggplot (dat_mm, aes (x = as.factor (time), y = value.x, ymin = value.x-value.y, ymax = value.x + value.y, fill = Variable + location = group)
Comments
Post a Comment