r - 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.
解决方案
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()
推荐阅读
- javascript - 从字符串中删除一个字符的函数
- java - 对数组进行排序的最简单方法是什么?
- vuejs2 - vue-material 表不适用于 v-slot 语法
- regex - Vim:如何替换字符串的多个实例,但仅限于该字符串中的某些分隔符之间
- c# - 处理 json 以写入文件的 WebAPI 控制器
- python - 在 python 中使用 matplotlib 时从 csv 文件中操作数据值
- reactjs - 使用 useReducer 更新状态时出现问题
- laravel - Laravel 从 5.5 升级到 5.6 到 5.7:未捕获 ReferenceError: axios is not defined
- rubygems - 无法在 redmine 迁移中捆绑更新和安装
- php - FormatException:输入意外结束(在字符 1 处)