ggplot2 / geom_bar

Hello,

I have a data frame with 26 observations and 6 variables dichotomous. This variables correspond to the day of the measure of mortality (J28 / J60 / J180 ...). The value of each variable are T or F.
I would like to make a bar graph with Ggplots, x = a variable and y = the proportion of T. I found for each variable but I would like to combine the set of these variables on my plot. Are you any idea ?

Thanks for your help,

Can you provide a sample of your dataset please? dput or tibble::tribble are good options for providing us a sample of your data.

1 Like

Like said @dvetsch75 , is important put an example of data for better help.

Maybe this could guide this work.

Var1 = c(1, 2, 4, 1, 2, 2, 3, 1, 5, 2, 2, 3, 4, 2, 2, 3, 5, 5, 2, 2, 3, 1, 4, 4, 5) 
Var2 = c(TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE)
df = data_frame(Var1, Var2)

ggplot(df, aes(Var1)) + geom_bar() + facet_grid(. ~Var2)

Thanks a lot for your answers ! Here, my code :

data$mort_eval_jour___1 = c(1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 
                            1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 
                            1, 0, 1, 0, 1, 1)
data$mort_eval_jour___2 = c(0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 
                            0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 
                            0, 1, 0, 1, 0, 0)
data$mort_eval_jour___3 = c(0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 
                            1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 
                            0, 0, 0, 1, 1, 0)
data$mort_eval_jour___4 = c(0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 
                            0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 
                            0, 0, 0, 0, 0, 0)
data$mort_eval_jour___5 = c(0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 
                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
                            0, 0, 0, 0, 0, 0)
data$mort_eval_jour___6 = c(0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 
                            0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 
                            0, 0, 0, 0, 0, 0)

label(data$mort_eval_jour___1)=
  "Evaluation mortalité : quand ? (choice = J28)"
label(data$mort_eval_jour___2)=
  "Evaluation mortalité : quand ? (choice = J60)"
label(data$mort_eval_jour___3)=
  "Evaluation mortalité : quand ? (choice = J90)"
label(data$mort_eval_jour___4)=
  "Evaluation mortalité : quand ? (choice = J180)"
label(data$mort_eval_jour___5)=
  "Evaluation mortalité : quand ? (choice = ICU)"
label(data$mort_eval_jour___6)=
  "Evaluation mortalité : quand ? (choice = hospit)"

data$mort_eval_jour___1.factor = factor(data$mort_eval_jour___1,
                                         levels=c("0","1"))
data$mort_eval_jour___2.factor = factor(data$mort_eval_jour___2,
                                         levels=c("0","1"))
data$mort_eval_jour___3.factor = factor(data$mort_eval_jour___3,
                                         levels=c("0","1"))
data$mort_eval_jour___4.factor = factor(data$mort_eval_jour___4,
                                          levels=c("0","1"))
data$mort_eval_jour___5.factor = factor(data$mort_eval_jour___5,
                                          levels=c("0","1"))
data$mort_eval_jour___6.factor = factor(data$mort_eval_jour___6,
                                           levels=c("0","1"))

levels(data$mort_eval_jour___1.factor) = c(F,T)
levels(data$mort_eval_jour___2.factor) = c(F, T)
levels(data$mort_eval_jour___3.factor) = c(F, T)
levels(data$mort_eval_jour___4.factor) = c(F, T)
levels(data$mort_eval_jour___5.factor) = c(F, T)
levels(data$mort_eval_jour___6.factor) = c(F, T)

mort_eval_jour <- data_frame(
  J28 = data$mort_eval_jour___1.factor,
  J60 = data$mort_eval_jour___2.factor,
  J90 = data$mort_eval_jour___3.factor,
  J180 = data$mort_eval_jour___4.factor,
  ICU = data$mort_eval_jour___5.factor,
  hosp = data$mort_eval_jour___6.factor
)

M_AcostaCH
I would like to have only the True of the variables on my plot !

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.