R 条形图百分比子组
我有一个数据集,其中包含来自csv的15个指标(列)。1个指标称为癌症 这就是数据集中的列的外观R 条形图百分比子组,r,R,我有一个数据集,其中包含来自csv的15个指标(列)。1个指标称为癌症 这就是数据集中的列的外观 Cancer: yes no yes no 我只想有一个条形图(堆叠和正常),显示癌症的是和否百分比 这应该使用ggplot2进行所需的堆叠打印 library(ggplot2) ggplot(df,aes(x="", fill = Cancer))+ #Do the bar plot scaled to 1 geom_bar(position = "fill") + #Chang
Cancer: yes no yes no
我只想有一个条形图(堆叠和正常),显示癌症的是和否百分比
这应该使用
ggplot2
进行所需的堆叠打印
library(ggplot2)
ggplot(df,aes(x="", fill = Cancer))+
#Do the bar plot scaled to 1
geom_bar(position = "fill") +
#Change the y axis labels as percent
scale_y_continuous(labels = scales::percent)
谢谢,它很管用。你能不能也做一个简单的表格,列出癌症的是/否百分比?但是我从不同的小组(筛选:年龄50-54岁,年龄出生第一个孩子)做了一个是/否的概述。这一个也适用,谢谢
library(ggplot2)
library(scales)
ggplot(df, aes(x = Cancer)) +
geom_bar(aes(y = (..count..)/sum(..count..))) +
scale_y_continuous(labels=scales::percent) +
labs(x="Cancer", y="Relative frequency [%]")
library(ggplot2)
ggplot(df,aes(x="", fill = Cancer))+
#Do the bar plot scaled to 1
geom_bar(position = "fill") +
#Change the y axis labels as percent
scale_y_continuous(labels = scales::percent)