生信技能树2021生信入门线上课笔记,需要结合课程讲解服用
常见可视化R包
作图:base, ggplot2, ggpubr
拼图:par里的mfrow, grid.arrange, cowplot, customLayout,patchwork
导出:pdf()等三段论, ggsave, eoffice---to pptx
length(unique(mpg$class))#class一列取值的个数
ggplot2习题
习题.pngggplot(data = iris,aes(x = Species, y = Sepal.Width)) +
geom_violin(aes(fill = Species)) +#用映射设置多个对象
geom_boxplot()+
geom_jitter(aes(shape = Species))+#点图,抖动
coord_flip()#翻转
#注意图层顺序,注意图的合理性
ggpubr 可以两两比较
ggpubr.pnglibrary(ggpubr)
ggscatter(iris,x="Sepal.Length",
y="Petal.Length",
color="Species")
p <- ggboxplot(iris, x = "Species",
y = "Sepal.Length",
color = "Species",
shape = "Species",
add = "jitter")#可以赋值
p
my_comparisons <- list( c("setosa", "versicolor"),
c("setosa", "virginica"),
c("versicolor", "virginica") )#两两比较的列表
p + stat_compare_means(comparisons = my_comparisons)+ # Add pairwise comparisons p-value
stat_compare_means(label.y = 9) #P值放的位置对应的纵坐标的值
labs()用于设置图表标题子标题、坐标名称等
p <- ggplot(mtcars, aes(mpg, wt, colour = cyl)) + geom_point()
p + labs(colour = "Cylinders")#把颜色标尺的标题设置为Cylinders
p + labs(x = "New x label")#把横坐标标题设置为New x label
# The plot title appears at the top-left, with the subtitle
# display in smaller text underneath it
#图表的标题默认设置在左上角,副标题以小一点的字号出现在主标题下面
p + labs(title = "New plot title")
p + labs(title = "New plot title", subtitle = "A subtitle")
# The caption appears in the bottom-right, and is often used for
# sources, notes or copyright
#图片说明默认设置在右下角,用于注释
p + labs(caption = "(based on data from ...)")
# The plot tag appears at the top-left, and is typically used
# for labelling a subplot with a letter.
#图片在左上角加tag和标题
p + labs(title = "title", tag = "A")
# If you want to remove a label, set it to NULL.
#去掉某个设置,设置为NULL
p + labs(title = "title") + labs(title = NULL)
ggplot(mtcars, aes(mpg, wt, colour = cyl)) +
geom_point() +
xlab(label = "New x lab") +#设置x轴标题
ylab(label = "New y lab") + #设置y轴标题
ggtitle(label = "This is title", subtitle = "This is subtitle")#设置标题和子标题
代码可运行却不出图---因为画板被占用
dev.off()关闭画板,多次运行直到null device,再运行,后者dev.new()
一些教程补充
-画图合集
https://www.jianshu.com/nb/35523479
-配色RColorBrewer
https://www.jianshu.com/p/194765c8c17e
-patchwork拼图
https://mp.weixin.qq.com/s/p7LLLvzR5LPgHhuRGhYQBQ
-ggplot2作图theme主题设置
https://blog.csdn.net/u014801157/article/details/24372531
网友评论