0

I’m trying to plot a barplot with 3 categoricals by one continuous variable. It’s easy to do in an excel or google spreadsheet, but the ggplot2 code is a bit hard. I tried modifying this but couldn't get it to work: https://www.r-bloggers.com/how-to-plot-three-categorical-variables-and-one-continuous-variable-using-ggplot2/. What I need is the y axis data (V) grouped by two time periods (0, 60) for one categorical group (NW, OB) and another (M,F) so you have four bars in two groups (by gender and by body weight). I’m using the mean values of V for each group rather than the whole dataset. The values are V0M 1.680 V0F 1.59 V60M 1.673, V60F 1.479, V0NW 1.679, V60NW 1.69 V0OB 1.613, V60OB 1.507

I tried variations of the code above but couldn’t make it work. The answer to Point Plot with SE for 3 Categorical & 1 Continuous Variable in R looks like it would work with the full dataset but I’ll have create another grouping equivalent to the “mea” variable, I think. The error bars would be nice but not essential. Can this be done in ggplot2 with only the means? Thanks in advance.

> dput(A0068tinyhead)
structure(list(A = c("", "", "1", "2", "3", "4"), B = c("", "gender", 
"F", "F", "F", "F"), C = c("", "b", "normal", "normal", "normal", 
"normal"), D = c("", "V0", "1.4", "1.98", "1.98", "1.91"), E = c("", 
"V0NW", "1.4", "1.98", "1.98", "1.91"), F = c("", "VOOB", "1.84", 
"1.75", "1.12", "1.75"), G = c("", "V0F", "1.4", "1.98", "1.98", 
"1.91"), H = c("", "V0M", "1.75", "1.45", "1.47", "1.86"), I = c("", 
"V60", "1.6", "1.77", "1.89", "1.63"), J = c("", "V60NW", "1.6", 
"1.77", "1.89", "1.63"), K = c("", "V60OB", "1.8", "1.51", "1.22", 
"1.1"), L = c("", "V60F", "1.6", "1.77", "1.89", "1.63"), M = c("", 
"V60M", "1.5", "1.73", "1.82", "1.55")), .Names = c("A", "B", 
"C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M"), row.names = c(NA, 
6L), class = "data.frame")

> dput(A0068tinytail)
structure(list(A = c("45", "46", "47", "48", "49", "50"), B = c("M", 
"M", "M", "M", "M", "M"), C = c("obese", "obese", "obese", "obese", 
"obese", "obese"), D = c("1.57", "1.81", "1.91", "1.69", "1.59", 
"1.78"), E = c("", "", "", "", "", ""), F = c("", "", "", "", 
"", ""), G = c("", "", "", "", "", ""), H = c("", "", "", "", 
"", ""), I = c("1.54", "1.63", "1.53", "1.54", "1.67", "1.5"), 
    J = c("", "", "", "", "", ""), K = c("", "", "", "", "", 
    ""), L = c("", "", "", "", "", ""), M = c("", "", "", "", 
    "", "")), .Names = c("A", "B", "C", "D", "E", "F", "G", "H", 
"I", "J", "K", "L", "M"), row.names = 47:52, class = "data.frame")
Community
  • 1
  • 1
JuanTamad
  • 65
  • 9
  • It would be helpful if you could provide the result of `dput` of your data and share what you have tried. – mt1022 Apr 25 '17 at 03:30
  • Ok, I need to simplify the data to just the variables needed. Few minutes. – JuanTamad Apr 25 '17 at 03:36
  • Says it loo long by 4000+ characters. What do I do? here's teh top: – JuanTamad Apr 25 '17 at 04:30
  • > dput(A0068tiny) structure(list(A = c("", "", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50"), B = c("", "gender", "F", "F", "F", "F", "F", "F", "F", "F", – JuanTamad Apr 25 '17 at 04:30
  • You can edit your post. – mt1022 Apr 25 '17 at 04:31
  • Don't understand, edit how? It won't allow to post the whole dput output. – JuanTamad Apr 25 '17 at 04:55
  • This might be helpful: http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example. You do not have to give all data. A small subset that will reproducible you problem is enough. – mt1022 Apr 25 '17 at 04:56
  • Use [this link](http://stackoverflow.com/posts/43600979/edit) to edit. – Axeman Apr 25 '17 at 05:15

0 Answers0