0%

用R给遗传实验报告添砖加瓦

需求:做一个拟南芥根长的次数分布直方图

library(readxl)
library(reshape2)
library(ggplot2)
#长宽转换 
data <- read_excel(“data.xlsx”)
reshape_data <- data.frame(data\`Mutant(mm)\`, data`Wild(mm)`)
reshape_data <- melt(reshape_data,
variable.name = “kind”,
value.name = “lenth”)
reshape_datakind=factor(reshape_datakind = factor(reshape\_datakind)
reshape_datakind<as.character(reshape_datakind<-as.character(reshape\_datakind)
reshape_datakind\[reshape\_datakind==‘data…Mutant.mm…’]=‘mutant’
reshape_datakind\[reshape\_datakind==‘data…Wild.mm…’]=‘wild’
class=“EnlighterJSRAW” data-enlighter-language=“generic”>ggplot(reshape_data, aes(x = lenth, fill = kind))+geom_histogram(alpha=0.5, bins = 8, aes(y=…density…))+geom_density(alpha=0.3,aes(color=kind))+
labs(title=“Inheritance of Root Length in Arabidopsis thaliana”, x=“Lenth(mm)”, y=“Density”)+theme(plot.title = element_text(hjust = 0.5))
class=“EnlighterJSRAW” data-enlighter-language=“generic”>ggsave(filename = ‘实验报告的图.png’,width = 8, height = 4)

实现后的效果: 实验报告的图-1024x512