用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_data$kind = factor(reshape_data$kind)
reshape_data$kind<-as.character(reshape_data$kind)
reshape_data$kind[reshape_data$kind=='data..Mutant.mm..']='mutant'
reshape_data$kind[reshape_data$kind=='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)

实现后的效果:

发表评论

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据