Analysis of binary variable

Hello! I am novice to R.
I am going through statistical analysis with R for my very first time. I hope you will help me.
I need to analyze a binary variable through 3 categories: I want the binary variable to be expressed as frequency on y-axis and the 3 categories on x-axis and have the trend line.
The binary variable is 1=dead, 0=alive, so for each category R should calculate the frequency of "1" over "0" and plot it. In MedCacl it was straightforward.
thank you for your attention.

Hi, welcome!

Homework inspired questions are welcome here, but you have to tell us what have you tried so far? what is your specific problem? We are more inclined towards helping you with specific coding problems rather than doing your work for you.

For guidelines about how to properly ask homework related questions here, please read our homework policy.

thank you for your reply.
it is not about homework, I just wanted to switch from medcalc to R.
i have a dataset with 3527 observation, each characterized by almost one hundred variables. I have already done the analysis with medcalc, I just want to reproduce it with R.
So observations are split into three temporal categories, and mortality (expressed as 0 or 1) needs to go on y-axis as frequency (read also as rate or incidence).
what i have tried is with ggplot:
b <- ggplot(dat, aes(x = eras, y = mean(INHOSPITAL)))

b + geom_point ()

To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue, that includes sample data on a copy/paste friendly format? Please have a look at this guide, to see how to create one:

Hi @adcar,

as it is your first post, I'll try to guess what you are trying to achieve. Given the iris dataset, I have created an iris2 data frame which has a status column which should resemble your binary variable. The 3 categories are in the Species column.

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(ggplot2)
iris2 <- iris %>% 
    group_by(Species) %>% 
    mutate(status = ifelse(Sepal.Length > mean(Sepal.Length), 1, 0)) %>% 
    ungroup()

iris2 %>% 
    group_by(Species) %>% 
    summarize(survived = mean(status)) %>% 
    ggplot(aes(x=Species, y=survived)) +
    geom_col() +
    theme_classic() +
    scale_y_continuous(labels = scales::percent_format(accuracy = 1))

Created on 2019-11-27 by the reprex package (v0.3.0)

thank you very much @valeri.

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