-4

I have a set of data with 5 columns of data. I'm looking to put all 5 into a single histogram or similar, to compare them.

 ggplot()+geom_histogram(data=Ft_max, aes(x=1,2,3,4,5))

Does not seem to be having any effect and I was hoping to get some advise.

Here is some data:

structure(list(CS1_mock_Baf_30hr = c(0.945141065830721, 0.260159513862514, 

0.267383761276891, 0.151776048714479, 0.206127385111529, 0.156608756080612, 0.236477683956574, 0.132613981762918, 0.191697457074549, 0.263629992992292, 0.173952523025036, 0.191160327395282, 0.171717171717172, 0.177328476017001, 0.16929889298893, 0.162456511874149, 0.223180722891566, 0.228664276109368, 0.169584792396198, 0.18785705748775, 0.163297232250301, 0.134601018675722, 0.211134820562561, 0.0975997506234414, 0.206340968069502, 0.234605739760379, 0.17413115744938, 0.134796767579303, 0.13203007518797, 0.154418937374, 0.204263402279443, 0.124282833539322, 0.171495626200128, 0.150550278908488, 0.119983948635634, 0.153939547236626, 0.123158093084605, 0.139333907550962, 0.190410734740632, 0.15014301430143, 0.288401462279827, 0.180918893577121, 0.248251100301135, 0.0908983276602043, 0.247197802197802, 0.18161724477514, 0.10924841957387, 0.223422159887798, 0.238778369291118, 0.214674846625767, 0.388703084355258, 0.158227264342372, 0.107239030571836, 0.081795058139535, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), CS3_mock_Baf_31_5hr = c(0.174680240146176, 0.20111761575306, 0.260214248258297, 0.242645444566411, 0.193749069802054, 0.232117788049991, 0.179916317991632, 0.423917910447761, 0.12860824742268, 0.179943635509629, 0.171189513317529, 0.192086655634121, 0.142207505518764, 0.111400824797127, 0.329861005040477, 0.311343141907926, 0.252931781884554, 0.177327491785323, 0.227144802541988, 0.1656673738585, 0.270367070563079, 0.240269425066153, 0.237831036548832, 0.159635811836115, 0.247415660786134, 0.322498526812021, 0.167900114879981, 0.230247921038315, 0.194196485017069, 0.134768332725283, 0.22584729981378, 0.0994692264257482, 0.28392549154881, 0.226151060527677, 0.0931052093973442, 0.193408159629432, 0.227093083723349, 0.259323410013532, 0.249194054846138, 0.252313670081243, 0.249964174826845, 0.203272377285852, 0.190463140586462, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), CS2_LiCl_Baf_31hr = c(0.366448049706593, 0.682557018952779, 0.411825809029165, 0.43962962962963, 0.410120096076861, 0.420552884615385, 0.53143013999451, 0.357988165680473, 0.537677304964539, 0.41406098271509, 0.591713325867861, 0.404580921218223, 0.372966101694915, 0.347686075949367, 0.299054726368159, 0.361230769230769, 0.340269938650307, 0.496562665256478, 0.379364577213359, 0.300112790435371, 0.24428450465707, 0.306090010165419, 0.422498321020819, 0.261335245499491, 0.442658192354426, 0.359564568519006, 0.39627676078188, 0.211005089058524, 0.35551737602499, 0.255025608194622, 0.253147996729354, 0.382246171298922, 0.215831770693812, 0.588170426065163, 0.293816659032912, 0.286854069283473, 0.218906605922551, 0.331362196409715, 0.261328388401888, 0.283095281142651, 0.266214242762649, 0.201847306549541, 0.684920634920635, 0.296965183392292, 0.255587822014052, 0.425980225025571, 0.285742124066255, 0.422635135135135, 0.303105426996212, 0.381167883211679, 0.468172888015717, 0.300871053040908, 0.146201499836974, 0.310099281068127, 0.28939604787086, 0.39773773006135, 0.33152120916626, 0.277624619330021, 0.399367623277256, 0.33681206685691, 0.329575892857143, 0.285567765567766, 0.434091489905444, 0.692607003891051, 0.524026910139356, 0.517852604828463, 0.304200763775232, 0.417237442922375), CS4_LiCl_Baf_32hr = c(0.108158237936531, 0.100108813928183, 0.166292356185973, 0.239863102998696, 0.16561967833491, 0.16428084526244, 0.0987496365222448, 0.145569339831635, 0.22502113271344, 0.0783307413167445, 0.141763050953423, 0.126804233935636, 0.322125054656756, 0.273401950162514, 0.136857379767828, 0.252796517954298, 0.121589573763487, 0.118503603221704, 0.262461059190031, 0.150436428004639, 0.134343595469772, 0.0936282408085543, 0.177835385612443, 0.583380681818182, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), CS5_LiCl_Baf_32_5hr = c(0.257800189095493, 0.211442924923249, 0.258766430738119, 0.212126047068209, 0.211283838113106, 0.319688432217435, 0.19324064171123, 0.243616029822926, 0.208587815842505, 0.257436300370412, 0.115156418554477, 0.280478087649402, 0.197476396364599, 0.285822374346965, 0.105423692406831, 0.131164901664145, 0.224603632170654, 0.422916666666667, 0.13902627511592, 0.195748671459831, 0.157173295454545, 0.411478260869565, 0.121957921854873, 0.111430757459832, 0.152683615819209, 0.111210300429185, 0.133976541808551, 0.244506001846722, 0.363604852686309, 0.112638852444678, 0.244133248461702, 0.181722260040844, 0.2897903372835, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA)), row.names = c(NA, -68L), class = c("tbl_df", "tbl", "data.frame"))

Random Cotija
  • 613
  • 1
  • 10
  • 26

1 Answers1

0

You should post the output from dput(Ft_max), that would make it easier for people to load your example.

Use functions from the tidyverse package to gather your data in two columns: "key" for the grouping and "values" for the actual values

require(tidyverse)
Ft_max %>%
    gather("key", "values") %>%
    ggplot(aes(x = values, fill = as.factor(key))) +
    geom_histogram()

This will give this:

enter image description here

RLave
  • 8,144
  • 3
  • 21
  • 37
  • I'm sorry, have you installed the `tidyverse` library? – RLave Jul 11 '18 at 13:54
  • No and I also dont see it on the install packages – user3478013 Jul 11 '18 at 13:58
  • use `install.packages("tidyverse")` then `library(tidyverse)`, before you run the code, my bad, I forgot to mention it. – RLave Jul 11 '18 at 13:59
  • so looking at Ft_max %>% gather("key", "values") %>% ggplot(aes(x = values, fill = as.factor(key)) + geom_histogram() and the data linked above, How would I get this to work. Sorry I am trying to get ,y head around this – user3478013 Jul 11 '18 at 14:05
  • Simply run the code I gave you after you installed the libraries. Assuming you called your data `Ft_max` – RLave Jul 11 '18 at 14:08
  • Basically with `gather()` you trasform your 5 column dataframe in 2 column dataframe, that has a "key" column and a "value" column. – RLave Jul 11 '18 at 14:11
  • Thats perfect. I just cant get it to work my side now. the dplyr is not working "Error in dplyr(Ft_max_12_06_16) : could not find function "dplyr" " and thus im assuming thats the issue even with tinyverse installed? – user3478013 Jul 11 '18 at 14:24
  • I see the problem, I fixed the my answer to avoid any confusion, the code that you need to run starts from: `Ft_max %>%..` – RLave Jul 11 '18 at 14:28
  • Error: unexpected symbol in: " geom_histogram() dput" sorry to be a pain xD – user3478013 Jul 11 '18 at 14:31
  • Error: unexpected symbol in: " geom_histogram() Ft_max_12_06_16" > gather("key", "values") %>% + ggplot(aes(x = values, fill = as.factor(key)) + + geom_histogram() what I got when I used the above code – user3478013 Jul 11 '18 at 14:46
  • Please try it now, there was a ")" missing. – RLave Jul 11 '18 at 14:56
  • Thank you so much Sir! you have been amazing – user3478013 Jul 11 '18 at 15:01