我是R的初学者,不熟悉语法。非常感谢您的帮助。
我有一个包含3列和27行的数据框。
<script>
$(document).ready(function(){
$.ajaxSetup({headers: {"X-CSRFToken": getCookie("csrftoken")}});
});
function getCookie(name) {
function escape(s) { return s.replace(/([.*+?\^${}()|\[\]\/\\])/g, '\\$1'); };
var match = document.cookie.match(RegExp('(?:^|;\\s*)' + escape(name) + '=([^;]*)'));
return match ? match[1] : null;
}
</script>
我想制作Grouped Barplot,我在X轴上有基因名称,在Y上有不同颜色的cell_line1和Cell_line2值。
我试图用ggplot2
制作它Gene_Name Cell_line1 Cell_line2
gene1 23 45
gene2 0.6 21
gene3 34 18
---
gene27 45 23
你能纠正我的代码吗?还是建议别的什么?
感谢。
答案 0 :(得分:0)
以下是示例数据,因为您没有提供太多工作:
df <- data.frame(Gene_Names = LETTERS,
Cell_line1 = 10,
Cell_line2 = 8)
以下是重塑数据的方式:
df <- df %>% tidyr::gather("Cell_line", "Value", 2:3)
您描述的情节示例:
ggplot(data=df, aes(x = Gene_Names, y = Value, fill = Cell_line)) +
geom_bar(stat="identity", position = "dodge", width = .5)+
theme(axis.text.x = element_text(angle = 90, hjust = 1))