Calculating Mean and SD by several groups in the dataframe - r

I have a set of data for which I need to calculate descriptive statistics such as Mean and SD. The trick is that there are two grouping variables that I am trying to use to compute these statistics. The end goal is to obviously plot the mean with SD as error bars but I've left that for the end. I am only able to compute the mean and SD grouped by 1 variable.
I have added some data from my dataset for all of you to understand what I'm trying to achieve. I want the mean and SD to be calculated for each variable for a particular treatment. For example, mean and SD for NBR for control, low, medium and high separately rather than mean for all values in NBR.
Any help would be greatly appreciated!
structure(list(Plot = structure(c(1L, 1L, 1L, 1L, 3L, 3L, 3L,
3L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 3L, 3L, 3L,
3L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 3L, 3L, 3L,
3L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 3L, 3L, 3L,
3L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 3L, 3L, 3L,
3L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 3L, 3L, 3L,
3L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 3L, 3L, 3L,
3L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 3L, 3L, 3L,
3L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 3L, 3L, 3L,
3L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 3L, 3L, 3L,
3L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 3L, 3L, 3L,
3L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 3L, 3L, 3L,
3L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 1L,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L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L,
12L, 12L, 12L, 12L, 12L, 12L, 12L, 13L, 13L, 13L, 13L, 13L,
13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 14L,
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L,
14L, 14L, 14L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L,
15L, 15L, 15L, 15L, 15L, 15L, 15L, 16L, 16L, 16L, 16L, 16L,
16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 17L,
17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L,
17L, 17L, 17L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L,
18L, 18L, 18L, 18L, 18L, 18L, 18L, 19L, 19L, 19L, 19L, 19L,
19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L,
21L, 21L, 21L, 21L, 21L, 21L, 21L, 22L, 22L, 22L, 22L, 22L,
22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L), .Label = c("NDVI",
"TCARI", "TCARI.OSAVI", "PRI", "WI", "MSI", "NDWI", "WI.NDVI",
"SIPI", "NPQI", "ARI1", "NPCI", "NBR", "BAI", "CSI", "MIRBI",
"dr525", "dr720", "dr705", "dr1550", "dr1030", "dr1215"), class = "factor"),
value = c(0.49052608, 0.561715025, 0.681058775, 0.418972935,
0.598040793, 0.325178174, 0.39611861, 0.482473151, 0.54914233,
0.326459616, 0.449550569, 0.374982537, 0.498916873, 0.157797056,
0.375598585, 0.369668549, 0.067487106, 0.056591414, 0.043807341,
0.051725487, 0.093754202, 0.015804118, 0.010208146, 0.069180561,
0.047256836, 0.014956843, 0.046819988, 0.024258394, 0.043112507,
0.00452289, 0.016060574, 0.019127195, 0.008477461, 0.006499842,
0.002487178, 0.010566068, 0.009558856, 0.002362453, 0.001000077,
0.011176193, 0.005692711, 0.001454276, 0.002671122, 0.004389175,
0.005963771, 0.000633278, 0.001738936, 0.00297559, -0.077436131,
-0.063224907, -0.04141906, -0.066029217, -0.078353929, -0.06269534,
-0.062645246, -0.071945342, -0.074503314, -0.039682707, -0.033944239,
-0.067220924, -0.068048716, -0.022911819, -0.055515436, -0.058149026,
0.954379644, 0.961920174, 0.97662393, 0.94470929, 0.967260471,
0.914987902, 0.913176432, 0.97220911, 0.964781397, 0.980127277,
0.959769039, 0.950881126, 0.944166816, 0.979386244, 0.936922322,
0.955133338, 1.175592718, 1.035411255, 0.800772417, 1.336485183,
0.901900085, 1.958346653, 1.803438856, 1.161775069, 0.991080828,
1.341931259, 1.367156399, 1.509288183, 1.312893994, 1.906225698,
1.55938558, 1.669204336, -0.152945727, -0.133348314, -0.094084016,
-0.171933735, -0.120064992, -0.224291293, -0.222158781, -0.118233127,
-0.122948258, -0.091499501, -0.158288059, -0.156905855, -0.182074425,
-0.146780258, -0.145409057, -0.192813307, 1.945624674, 1.712470081,
1.433978924, 2.254821761, 1.617382095, 2.813804784, 2.305310603,
2.015053288, 1.756887684, 3.002292558, 2.134952338, 2.535801087,
1.892433123, 6.206619232, 2.494477773, 2.583756021, 0.742911497,
0.780168303, 0.843457583, 0.65195971, 0.830975899, 0.574818388,
0.616816538, 0.719949791, 0.772449293, 0.53750892, 0.731024759,
0.612688442, 0.716754763, 0.252652391, 0.578930733, 0.572089182,
-0.100561356, -0.099296831, -0.092483347, -0.075723921, -0.142851785,
-0.089130121, -0.04298129, -0.102317471, -0.106134004, -0.071568325,
-0.037759085, -0.074943034, -0.082143985, -0.013550746, -0.042738224,
-0.052687304, 5.676531166, 6.233612201, 7.784421521, 3.641213998,
5.227190069, 9.309509369, 20.49898004, 3.561438434, 6.481028072,
11.57997948, 5.13213622, 5.522131497, 6.185040981, 7.365686981,
13.08585062, 6.613297282, 0.454955786, 0.474862574, 0.426419642,
0.416520911, 0.508605292, 0.419544434, 0.392348758, 0.434385238,
0.481246028, 0.30321057, 0.306903479, 0.418355778, 0.437338379,
0.13683308, 0.344513171, 0.355125174, 0.326893516, 0.387399288,
0.515154218, 0.182065945, 0.500676583, -0.209412435, -0.076292248,
0.241900919, 0.365695503, -0.114812299, 0.054850362, -0.014567095,
0.236467347, -0.44330064, -0.169288639, -0.063890848, 9.714595654,
8.915965336, 13.82459669, 6.675855319, 6.569665271, 21.75446394,
36.33854707, 6.696758415, 8.98382931, 38.25326354, 30.84745383,
11.95769473, 9.717936813, 42.50114638, 30.2370565, 16.44987732,
0.937570572, 1.067734668, 1.381944935, 0.81371232, 1.234718748,
0.537791913, 0.594631013, 0.919821798, 1.108794746, 0.775895297,
0.775232557, 0.698743732, 0.835058861, 0.53024459, 0.671650699,
0.632847585, 0.759036354, 0.783179738, 1.238926572, 0.505364128,
0.516207899, 1.726260299, 1.740690206, 0.673977376, 0.93851288,
1.992771034, 1.706586328, 1.351753865, 0.71549755, 2.224957641,
1.954708561, 1.480237458, 0.000674694, 0.000664894, 0.000510151,
0.000696155, 0.000952195, 0.000223176, 0.000117448, 0.000866633,
0.000569965, 0.000152732, 0.000509423, 0.000387613, 0.000515502,
5.22e-05, 0.000179509, 0.000274014, 0.001953683, 0.002430971,
0.002398101, 0.002139202, 0.003496132, 0.000307836, 0.000251248,
0.002999544, 0.002325187, 0.000269912, 0.000755669, 0.001121944,
0.001959135, 0.000112208, 0.000368882, 0.000816404, 0.002392897,
0.002322436, 0.00184051, 0.002173463, 0.003689693, 0.000462046,
0.000309551, 0.002912204, 0.002086132, 0.00041697, 0.001201466,
0.001087332, 0.001915154, 0.000122092, 0.000485394, 0.000828789,
0.000452513, 0.000597348, 0.000447671, 0.000567325, 0.000644769,
0.000219354, 0.000211073, 0.000596602, 0.000469899, 9.16e-05,
0.000291864, 0.000349806, 0.00054511, 6.09e-05, 0.000205434,
0.000265793, 0.000319714, 0.000274149, 0.000279715, 0.000402482,
0.000500617, 0.000228484, 9.38e-05, 0.000318863, 0.000378217,
2.97e-05, 0.000130812, 0.000221053, 0.000385489, 9.62e-06,
6.79e-05, 0.000215798, 0.00034812, 0.000394904, 0.000240183,
0.000427487, 0.000415141, 0.000205784, 0.000123726, 0.000314875,
0.000378047, 5.26e-05, 0.000105128, 0.000218972, 0.000400508,
4.07e-05, 8.06e-05, 0.000233541)), .Names = c("Plot", "Landcover",
"Epoch", "Index_Name", "value"), row.names = c(NA, -352L), class = "data.frame")

mean(df$value[df$Plot == 'control' & df$Index_Name == 'NBR'])
summary(df$value[df$Plot == 'control' & df$Index_Name == 'NBR'])
is it what you want?
df$Plot == 'control' & df$Index_Name == 'NBR'
can choose 'control' and 'NBR'
it return a logical varible,so df$value[df$Plot =='control' & df$Index_Name == 'NBR'] can choose the value for for NBR and control.
Similarly,
mean(df$value[df$Plot == 'low' & df$Index_Name == 'NBR'])
mean(df$value[df$Plot == 'medium ' & df$Index_Name == 'NBR'])
mean(df$value[df$Plot == 'high' & df$Index_Name == 'NBR'])

Related

How to reshape conjoint data from wide to long?

users,
I have received a data from a conjoint survey experiment. What I want to do is to reshape from wide to long format. However, this seems to be slightly complicated. I am pretty sure it is possible to do with cj_tidy (package cregg) but can't solve it myself.
In the survey, the respondents were asked to compare two organizations that vary across 7 profiles (Efficiency Opennes Inclusion Leader Gain & System). In total, respondents were presented with four comparisons. So 2 organizations and 4 comparisons (4x2). They had to choose one of the presented organization and rate them separately after choosing one.
At the moment, the profile variables are structured in this way: org1_Efficiency_conj_1, org1_Opennes_conj1 ..etc. The first part "org" indicates whether it is the first or second organization. The last part "conj", indicated the order of the conjoint/comparison, where the "conj4" is the last comparison. The CHOICE variables also follow the order of conjoint – for example,"CHOICE_conj1", "CHOICE_conj2", where =1 means the respondent chose "org1". If =2, then org2 was chosen. The RATING> variable indicates a value from 0 to 10 for each organization: RATING_conj1_org1; RATING_conj1_org2 etc..
The current wide format of the data is not suitable for conjoint analysis - what I need is to create 8 observations for each respondent (4x2=8) where the variable CHOICE would indicate which of the organizations were chosen (where =1 if yes; and =0 if no). In a similar way, the variable RATING should indicate the rating given by respondents for both of the organizations (0 to 10).
This is how I would like the data to look like:
Note please that there are also covariates such as Q1 and Q2 in the picture, they are not a part of the experiment and should remain constant for each individual observation.
Below I share 50 observations from my real data.
> dput(cjdata_wide) structure(list(ID = 1:50, org1_Effeciency_conj_1 =
> c(3L, 2L, 1L, 3L, 3L, 2L, 3L, 3L, 3L, 3L, 2L, 1L, 1L, 1L, 1L, 1L, 3L,
> 2L, 3L, 3L, 3L, 2L, 3L, 1L, 2L, 1L, 3L, 3L, 1L, 1L, 3L, 1L, 1L, 3L,
> 3L, 2L, 3L, 2L, 3L, 2L, 1L, 1L, 3L, 2L, 1L, 1L, 1L, 2L, 2L, 1L ),
> org1_Oppenes_conj_1 = c(3L, 3L, 1L, 3L, 1L, 3L, 2L, 3L, 2L, 3L, 1L,
> 1L, 1L, 2L, 3L, 2L, 2L, 1L, 3L, 1L, 1L, 1L, 1L, 3L, 3L, 3L, 1L, 3L,
> 1L, 2L, 2L, 3L, 2L, 2L, 1L, 3L, 1L, 3L, 2L, 2L, 1L, 2L, 3L, 3L, 3L,
> 3L, 3L, 2L, 3L, 1L), org1_Inclusion_conj_1 = c(2L, 1L, 1L, 2L, 2L,
> 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 2L, 1L, 2L, 1L, 1L, 1L, 1L,
> 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 2L, 2L, 1L, 1L, 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5L, 3L, 3L,
> 3L, 3L, 4L, 5L, 5L, 4L, 2L, 3L)), class = "data.frame", row.names =
> c(NA,
> -50L))
What I have done so far is this:
library(cregg)
str(long <- cj_tidy(cjdata_wide,
profile_variables = c("All the profile variables"),
task_variables = c("CHOICE AND RATING VARIABLES HERE"),
id = ~ id))
stopifnot(nrow(long) == nrow(data)*4*2
But I'm keep getting errors. I have tried to follow the example given by the cregg package - but with no success. Any help is much appreciated! I am open to all possible ways, be it so through cregg package or tidyr for instance.
Your data not being in a standard form mades this a difficult problem. Here is a solution using the tidyr package.
The solutions involves 3 parts, dealing with the profiles, the rating and finally the rating choice.
The key to the profiles part was to pivot long and breaking up the profile names into component parts and then pivot wider for the column headings.
The rating and binary choice involved pivoting longer and then aligning the rows.
library(tidyr)
library(dplyr)
#Get the categories part correct
answer <-cjdata_wide %>% pivot_longer(cols=starts_with("org"), names_to=c("org", "Cat", "conj", "order"), values_to= "values", names_sep="_") %>% select(-c("conj"))
answer <-answer %>% select(!starts_with("RATING") & !starts_with("CHOICE"))
answer <-pivot_wider(answer, names_from = "Cat", values_from = "values")
#get the ratings column corretn
rating <-cjdata_wide %>% select(starts_with("RATING") )
rating <- rating%>% pivot_longer(cols=everything(), names_to=c("Rating", "conj", "order"), values_to= "Choice_Rating", names_sep="_") %>% select(-c("conj"))
answer$Choice_Rating <- rating$Choice_Rating
#Get the choice correct
choice <-cjdata_wide %>% select(starts_with("CHOICE") )
choiceRate <- choice%>% pivot_longer(cols=everything(), names_to=c("Choice", "conj"), values_to= "Choice_Rating", names_sep="_") %>% select(-c("conj"))
answer$Choice_binary <-ifelse(substr(answer$org, 4,4) == rep(choiceRate$Choice_Rating,each=2), 1, 0)
answer
It may be possible to simplify the above. Good luck.
Update per Comment
The final data frame has pairs of rows which corresponds to org 1 or 2. I duplicated the choice so that Choice_Rating column is the same length as the Organization ("org" column). I then compared Choice_Rating & Organization and setting the final value to either 0 or 1 depending on the match.
For question in the comment, A simple way is to convert the factor column to integers with as.integer() function, then the first factor becomes 1 and the second becomes 2 etc. (may need to relevel in order to get the proper order).
Another option is to create a new "org" column with your factor names properly listed.
Hopefully this provides enough guidance.

barchart - axis ticks are not adjusted according to the bars

I have to draw a bar chart in R ggplot2 with multiple variables (i.e each bar for BMI, weight, cholesterol, Blood pressure etc) in each group ( i.e. different populations ex: Indian, Korean, Philipinos etc.) But the bars are overflowing to the next group in the axis. for example: the bars of the Indian group is overflowing to Korean group. The axis marks are not adjusted accordingly. I have attached the figure .. can someone please help. Following is my code. dput(data) is also given.
p = ggplot(data = t,
aes(x = factor(Population, levels = names(sort(table(Population), increasing = TRUE))),
y = Snp_Count,
group = factor(Trait, levels = c("BMI", "DBP", "HDL", "Height", "LDL", "TC", "TG", "WC", "Weight"),
ordered = TRUE)))
p = p + geom_bar(aes(fill = Trait),
position = position_dodge(preserve = "single"),
stat = "identity") +
scale_fill_manual(values = c("#28559A", "#3EB650", "#E56B1F", "#A51890", "#FCC133", "#663300", "#6666ff", "#ff3300", "#ff66ff")) +
coord_flip()
structure(list(Trait = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 9L), .Label = c("BMI",
"DBP", "HDL", "HT", "LDL", "TC", "TG", "WC", "Weight"), class = "factor"),
Association = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L), .Label = "Direct", class = "factor"), TraitClass = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("Anthropometric",
"BP", "Lipid"), class = "factor"), Population = structure(c(2L,
3L, 4L, 5L, 7L, 8L, 10L, 11L, 12L, 13L, 22L, 24L, 3L, 5L,
11L, 22L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L,
14L, 15L, 18L, 20L, 28L, 5L, 7L, 13L, 14L, 1L, 3L, 5L, 7L,
9L, 11L, 12L, 16L, 18L, 20L, 22L, 5L, 6L, 7L, 10L, 12L, 18L,
20L, 3L, 5L, 6L, 7L, 8L, 11L, 12L, 13L, 14L, 15L, 18L, 19L,
20L, 21L, 22L, 23L, 26L, 28L, 3L, 4L, 5L, 8L, 12L, 22L, 24L,
3L, 5L, 7L, 8L, 17L, 25L, 27L), .Label = c("ACB", "AFR",
"ASW", "ASW/ACB", "CEU", "CHB", "EAS", "Filipino", "FIN",
"GBR", "Hispanic", "Hispanic/Latinos", "JPT", "Korean", "Kuwaiti",
"Micronesian", "Moroccan", "MXL", "Mylopotamos", "Orcadian",
"Pomak", "SAS", "Saudi_Arabian", "Seychellois", "Surinamese",
"Taiwanese", "Turkish", "YRI"), class = "factor"), Snp_Count = c(3L,
12L, 6L, 17L, 2L, 10L, 1L, 6L, 3L, 3L, 10L, 6L, 1L, 1L, 1L,
1L, 2L, 1L, 10L, 1L, 1L, 2L, 1L, 2L, 1L, 1L, 3L, 1L, 1L,
2L, 1L, 2L, 20L, 5L, 4L, 1L, 1L, 2L, 7L, 2L, 1L, 1L, 1L,
1L, 1L, 1L, 2L, 8L, 2L, 4L, 3L, 1L, 2L, 1L, 4L, 20L, 5L,
11L, 2L, 4L, 3L, 4L, 2L, 3L, 4L, 1L, 1L, 1L, 2L, 2L, 1L,
2L, 3L, 2L, 4L, 4L, 1L, 4L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L
), Gene_Count = c(3L, 9L, 7L, 9L, 2L, 8L, 1L, 7L, 3L, 2L,
8L, 7L, 1L, 1L, 1L, 1L, 2L, 1L, 4L, 1L, 1L, 1L, 1L, 2L, 2L,
1L, 2L, 1L, 1L, 1L, 1L, 1L, 9L, 6L, 5L, 1L, 1L, 2L, 5L, 2L,
1L, 1L, 1L, 1L, 1L, 1L, 2L, 6L, 2L, 3L, 3L, 1L, 2L, 1L, 3L,
10L, 4L, 7L, 1L, 3L, 3L, 4L, 1L, 3L, 5L, 1L, 1L, 1L, 3L,
3L, 1L, 1L, 2L, 2L, 3L, 3L, 1L, 3L, 2L, 3L, 3L, 2L, 3L, 2L,
2L, 2L)), class = "data.frame", row.names = c(NA, -86L))
The total width of each group in your barchart is 0.9 by default, which means that 90% of the area is covered. When you increase the width of the individual bars to 3 they will overlap with other groups, the maximum value for with should thus be 1 and then it will touch the other groups.
I'd suggest in your situation to use facet_wrap instead of a dodged barchart.
Note: geom_col is the same as geom_bar(stat = "identity).
my.df$Trait <- factor(my.df$Trait, levels = c("BMI", "DBP", "HDL", "HT", "LDL", "TC", "TG", "WC", "Weight"))
my.df$Population <- factor(my.df$Population, levels = names(sort(table(my.df$Population), increasing = TRUE)))
ggplot(my.df, aes(x = Trait, y = Snp_Count, fill = Trait)) +
geom_col(width = 1) +
scale_fill_manual(values = c("#28559A", "#3EB650", "#E56B1F", "#A51890", "#FCC133", "#663300", "#6666ff", "#ff3300", "#ff66ff")) +
# Split the data by Population, allow flexible scales and spacing for y axis (Trait)
facet_grid(Population ~ ., scales = "free_y", space = "free_y", switch = "y") +
coord_flip() +
theme(axis.text.y = element_blank(), # Remove Trait labels (indicated by color)
axis.ticks.y = element_blank(), # Remove tick marks
strip.background = element_blank(),
strip.text.y = element_text(angle = 180, hjust = 1), # Rotate Population labels
panel.spacing.y = unit(3, "pt")) # Spacing between groups
Data
my.df <-
structure(list(Trait = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 9L),
.Label = c("BMI", "DBP", "HDL", "HT", "LDL", "TC", "TG", "WC", "Weight"), class = "factor"),
Population = structure(c(2L, 3L, 4L, 5L, 7L, 8L, 10L, 11L,
12L, 13L, 22L, 24L, 3L, 5L, 11L, 22L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 18L, 20L, 28L, 5L,
7L, 13L, 14L, 1L, 3L, 5L, 7L, 9L, 11L, 12L, 16L, 18L, 20L,
22L, 5L, 6L, 7L, 10L, 12L, 18L, 20L, 3L, 5L, 6L, 7L, 8L,
11L, 12L, 13L, 14L, 15L, 18L, 19L, 20L, 21L, 22L, 23L, 26L,
28L, 3L, 4L, 5L, 8L, 12L, 22L, 24L, 3L, 5L, 7L, 8L, 17L,
25L, 27L),
.Label = c("ACB", "AFR", "ASW", "ASW/ACB", "CEU",
"CHB", "EAS", "Filipino", "FIN", "GBR", "Hispanic", "Hispanic/Latinos",
"JPT", "Korean", "Kuwaiti", "Micronesian", "Moroccan", "MXL",
"Mylopotamos", "Orcadian", "Pomak", "SAS", "Saudi_Arabian",
"Seychellois", "Surinamese", "Taiwanese", "Turkish", "YRI"), class = "factor"),
Snp_Count = c(3L, 12L, 6L, 17L, 2L,
10L, 1L, 6L, 3L, 3L, 10L, 6L, 1L, 1L, 1L, 1L, 2L, 1L, 10L,
1L, 1L, 2L, 1L, 2L, 1L, 1L, 3L, 1L, 1L, 2L, 1L, 2L, 20L,
5L, 4L, 1L, 1L, 2L, 7L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 8L,
2L, 4L, 3L, 1L, 2L, 1L, 4L, 20L, 5L, 11L, 2L, 4L, 3L, 4L,
2L, 3L, 4L, 1L, 1L, 1L, 2L, 2L, 1L, 2L, 3L, 2L, 4L, 4L, 1L,
4L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L)),
class = "data.frame", row.names = c(NA, -86L))

Histogram does not align/correspond to x-axis in ggplot/R

I have a histogram illustrating a specific cell count on the x-axis (1 = 1 cell counted, 2 = 2 cells counted etc), and how many patients that cumulative have been diagnosed with this specific cell count on the y-axis.
However, the "base" of the histogram does not align with the specific value on the x-axis. Preferably, I want the x-axis-cell-count to be be centered in the base of the histogram.
I have attached a photo of how it looks ATM:
My data
p <– structure(list(WHO.Grade = c(1L, 1L, 1L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3L, 3L, 3L, 3L, 1L, 4L, 5L, 2L, 3L, 3L, 5L, 7L, NA, 2L, 12L, 4L, 0L, 4L, 3L, 10L, 5L, 4L, 3L, 20L, 10L, 10L, 3L, 2L, 10L, 4L, 5L, 3L, 2L, 4L, 2L, 5L, 2L, 4L, 25L, 3L, 5L, 3L, 4L, 7L, 0L, 5L, 7L, 1L, 1L, 1L, 4L, 4L, 6L, 5L, 7L, 3L, 3L, NA, 3L, 4L, 3L, 5L, 10L, 1L, 2L, 3L, 2L, 4L, 5L, 4L, 3L, 4L, 3L, 3L, 7L, 3L, 4L, 3L, 4L, 5L, 6L, 3L, 2L, 3L, 4L, 5L, 3L, 4L, 2L, 4L, 5L, 5L, 12L, 12L, 7L)), .Names = c("WHO.Grade", "ki67pro"), class = "data.frame", row.names = c(NA, -176L))
p1 <- subset(p, p$WHO.Grade==1)
p2 <- subset(p, p$WHO.Grade==2)
p3 <- subset(p, p$WHO.Grade==3)
I have used the follow script:
q <- ggplot() + theme_grey() +
scale_x_continuous(name="The Ki-67/MIB-1 LI percetage", limits=c(-1, 26), seq(-1,26,by=1)) +
scale_y_continuous(name="Patients diagnosed", limits=c(0, 44), seq(0,44,by=2)) +
geom_histogram(aes(x=p1$ki67pro), colour="#222a37", fill="#222a37", bins=40, alpha=0.30) +
geom_histogram(aes(x=p2$ki67pro), colour="dodgerblue2", fill="dodgerblue2", bins=40, alpha=0.35) +
geom_histogram(aes(x=p3$ki67pro), colour="darkred", fill="darkred", bins=40, alpha=0.35) +
geom_density(aes(x=p$ki67pro, y=..count..), colour="orange", fill="white", alpha=0) +
geom_hline(yintercept=0, colour="white", size=0.9)
q
Thanks, C.
Going off of my comment, replacing geom_hist with geom_bar and removing the bin argument gets you:

How do I reduce this data frame by groups?

I have the following
t <- structure(list(name = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L), .Label = c("Alice", "Bob",
"Jane Doe", "John Doe"), class = "factor"), school = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L), .Label = c("Alice School",
"Bob School", "Someother School", "Someschool College"), class = "factor"),
group = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("A", "B"), class = "factor"),
question = structure(c(2L, 4L, 6L, 8L, 1L, 3L, 5L, 7L, 2L,
4L, 6L, 8L, 1L, 3L, 5L, 7L, 2L, 4L, 6L, 8L, 1L, 3L, 5L, 7L,
2L, 4L, 6L, 8L, 1L, 3L, 5L, 7L), .Label = c("q1", "q2", "q3",
"q4", "q5", "q6", "q7", "q8"), class = "factor"), mark = c(0L,
0L, 0L, 0L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L,
1L, 1L, 0L, 1L, 0L, 1L, 0L, 1L, 0L, 1L, 1L, 0L, 1L, 0L, 1L,
1L), subject = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L,
1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L,
2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L), .Label = c("C", "M"), class = "factor")), .Names = c("name",
"school", "group", "question", "mark", "subject"), row.names = c(7L,
15L, 23L, 31L, 3L, 11L, 19L, 27L, 8L, 16L, 24L, 32L, 4L, 12L,
20L, 28L, 6L, 14L, 22L, 30L, 2L, 10L, 18L, 26L, 5L, 13L, 21L,
29L, 1L, 9L, 17L, 25L), class = "data.frame")
and I need to produce a data frame in which each student has one combined mark for each subject. The combination is simply a sum of the marks on each question. So, for example, Jane Doe will have 3 on subject C and 2 on subject M. I've been banging my head for long enough with Reduce and other approaches. I could possibly solve this in a very procedural way, but if I could do that with a one-liner (or close approximation), I'd be happier. I'm sure it can be done...
You said it in your question; you want to group_by student and subject and compute the sum
library(tidyverse)
asdf %>%
group_by(name, subject) %>%
summarise(score = sum(mark))
Here a data.table solution:
library(data.table)
setDT(t)[, sum(mark), by = list(name, subject)]
And just for completeness, base R:
aggregate(mark ~ name + subject, data=t, sum)
This says "aggregate the response variable mark by the grouping variables name and subject, using sum as the aggregation function".

Negative Binomial in R: glm.nb: In sqrt(1/i) : NaNs produced, and other problems

I am running a negative binomial regression.
I would like to know why I have the following errors:
In sqrt(1/i) : NaNs produced
It appears that there are some negative values in "i", but how do I avoid that?
Another one is:
In loglik(n, th, mu, Y, w) : value out of range in 'lgamma'
It is probably a consequences of the first error, so if I fix the first one, the second might be gone. Or maybe not.
In some other cases I am able to calculate the regression but the following output seems strange for me:
(Dispersion parameter for Negative Binomial(10684331573) family taken
to be 1)
Null deviance: 8779.49 on 359 degrees of freedom
Residual deviance: 270.32 on 200 degrees of freedom
AIC: 2074.7
Number of Fisher Scoring iterations: 1
Theta: 10684331573
Std. Err.: 615849693813
2 x log-likelihood: -1752.749
Do these numbers seem okay? I mean the dispersion parameter, theta and standard error. They look enormously big to me and therefore I am not sure if the results are okay.
I never had any problems like that using poisson regression, but then I realized that I have an overdispersed data and that is why I am using negative binomial. However, I am having a lot of troubles with this one.
Here is the code:
negbin <- glm.nb(Freq ~ cluster*gender*agecombined*educ, maxit=100)
mod.good <- step(negbin, direction='both', maxit=100)
And here is the dput of the whole dataset:
structure(list(gender = structure(c(1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L,
1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L,
2L, 1L, 2L, 1L, 2L, 1L, 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L, 26L, 44L, 34L, 54L, 25L, 41L, 19L, 17L, 10L, 3L, 3L,
0L, 4L, 4L, 7L, 14L, 22L, 31L, 14L, 34L, 14L, 33L, 14L, 20L,
7L, 11L, 22L, 11L, 14L, 8L, 8L, 1L, 2L, 0L, 1L, 2L, 29L,
65L, 34L, 84L, 36L, 65L, 28L, 39L, 16L, 15L, 16L, 9L, 25L,
51L, 12L, 38L, 23L, 29L, 22L, 19L, 7L, 5L, 5L, 1L, 7L, 16L,
14L, 35L, 6L, 27L, 8L, 5L, 1L, 1L, 1L, 0L, 24L, 57L, 29L,
53L, 24L, 28L, 11L, 9L, 7L, 2L, 0L, 0L, 3L, 7L, 1L, 8L, 2L,
18L, 5L, 13L, 10L, 11L, 5L, 10L, 3L, 1L, 5L, 13L, 4L, 2L,
2L, 1L, 1L, 0L, 0L, 0L, 14L, 51L, 21L, 77L, 23L, 50L, 25L,
31L, 17L, 16L, 13L, 13L, 19L, 52L, 24L, 59L, 18L, 44L, 9L,
20L, 6L, 3L, 7L, 2L, 14L, 28L, 34L, 47L, 29L, 47L, 15L, 13L,
9L, 3L, 2L, 0L, 46L, 75L, 124L, 81L, 67L, 45L, 33L, 15L,
9L, 4L, 5L, 3L, 0L, 10L, 6L, 19L, 12L, 28L, 22L, 37L, 31L,
41L, 26L, 31L, 7L, 6L, 21L, 13L, 6L, 7L, 8L, 2L, 2L, 1L,
0L, 0L, 67L, 89L, 116L, 159L, 99L, 102L, 64L, 80L, 42L, 25L,
25L, 8L, 108L, 123L, 60L, 97L, 68L, 66L, 44L, 35L, 12L, 5L,
9L, 2L, 7L, 3L, 53L, 15L, 33L, 3L, 8L, 3L, 4L, 0L, 0L, 0L,
48L, 19L, 76L, 40L, 55L, 11L, 16L, 1L, 4L, 1L, 2L, 0L, 6L,
7L, 21L, 22L, 18L, 23L, 32L, 37L, 40L, 13L, 23L, 10L, 4L,
2L, 19L, 2L, 8L, 3L, 6L, 0L, 1L, 0L, 1L, 0L, 68L, 37L, 90L,
42L, 76L, 38L, 47L, 16L, 29L, 5L, 18L, 2L, 82L, 32L, 62L,
27L, 44L, 22L, 20L, 8L, 8L, 2L, 1L, 0L)), .Names = c("gender", "agecombined", "educ", "cluster", "Freq"), row.names = c(NA,
-360L), class = "data.frame")

Resources