如何使用以下数据框绘制堆积条形图
数据框低于
tata4 <- data.frame(Subtype = c("Prostate", "Oesophagus", "Lung"),
alive = c(88, 22, 100), dead = c(12, 55, 17),
uncertain = c(10, 2, 2), total = c(186,46,202))
我想要的是这个 - 每个“前列腺”、“食道和肺”的堆叠条形图。根据每种癌症,这些列应垂直细分为存活数、死亡数和不确定数。 (每个条形显示总数)。
我正在努力寻找正确的代码。我似乎无法找到一种方法使“填充”函数成为每个肿瘤部位的值。
有人可以帮忙吗?
dataframe is below
tata4 <- data.frame(Subtype = c("Prostate", "Oesophagus", "Lung"),
alive = c(88, 22, 100), dead = c(12, 55, 17),
uncertain = c(10, 2, 2), total = c(186,46,202))
what I want is this - A stacked barplot for each of the 'prostate', 'oesophagus and Lung. The columns should be subdivided vertically into the number alive,dead and uncertain according to each cancer. (with each bar displaying the total).
I'm struggling to find the right codes. I can't seem to find a way of making the 'fill' function the values of each tumour site.
Can someone please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您需要将数据转换为长格式:
然后您可以将数据提供给 ggplot:
给出:
< img src="https://i.sstatic.net/6gR8Z.jpg" alt="在此处输入图像描述">
我不确定您要在哪里绘制或注释
总计
First you need to bring your data into long format:
Afterwards you can feed the data to ggplot:
Which gives:
I am not sure where you want to plot or annotate the
total