首页 > 解决方案 > creating a barplot showing frequency of samples using carcinoma dataset

问题描述

I was working on an assignment and I came across a problem that I am confused on. I am a beginner level R studio user and am unsure how to do this problem. I know how to make general barplots, but I am thrown off by how to make this specific barplot, especially subtracting 1. This is working with the carcinoma dataset.

Any help would be greatly appreciated! Thanks.

enter image description here

标签: rstatistics

解决方案


The carcinoma data comes from the poLCA package.

library(poLCA)
data(caricoma)
?carcinoma

According to the help page, the data represent dichotomous ratings by seven pathologists. 1="no" and 2="yes". So subtracting 1 and taking the column sums should give you the frequencies for each pathologist.

colSums(carcinoma-1)
# A  B  C  D  E  F  G 
#66 79 45 32 71 25 66 

Graphing is facilitated by reshaping into long form so we get only two columns.

library(tidyverse)

carcinoma %>%
  pivot_longer(everything()) %>%
  mutate(value=value-1) %>%
  ggplot(aes(x=name, y=value)) +
  geom_col()

enter image description here


推荐阅读