作图目的:展示自己的数据
略显陈旧
plot(iris[,1],iris[,3],col = iris[,5]) #点图,指定横纵坐标、颜色
text(6.5,4, labels = 'hello')#在坐标(6.5,4)加一个标记'hello'
ggplot(data = iris) +
geom_point(mapping = aes(x = Sepal.Length, y = Petal.Length),
color="blue",#点的颜色
size = 3, # 点的大小5mm
alpha = 0.5, # 透明度 50%
shape = 8) # 点的形状
默认红绿蓝
ggplot(data = iris)+
geom_point(mapping = aes(x = Sepal.Length,
y = Petal.Length,
color = Species))+
scale_color_manual(values = c("blue","grey","red"))#指定映射的颜色
使用现成的配色方案(ggplot2中内置了RColorBrewer)
获取此包中所有配色方案
library(RColorBrewer)
display.brewer.all(type = "all")
根据数据特点选择配色方案
离散型颜色(离散型)、单种颜色渐变色(连续型)、两种颜色渐变色(连续型)
ggplot(data = iris)+
geom_point(mapping = aes(x=Sepal.Length,
y=Petal.Length,
color=Species))+
scale_color_brewer(palette = "Set2")
区分color和fill
color是图形颜色,fill在又有边框又有填充色时使用
ggplot(data = iris)+
geom_point(mapping = aes(x = Sepal.Length,
y = Petal.Length,
color = Species),
shape = 24,
fill = "black")+
scale_color_brewer(palette = "Set2")
ggplot(data = iris,mapping = aes(x = Species,
y = Sepal.Width,
fill = Species)) + #箱型图应用fill填充颜色
geom_boxplot()+
geom_jitter()+ #加入随机,使点在图中不重叠
theme_bw()#改变主题(去除灰格背景)
pdf("iris_box_ggpubr.pdf")#保存的函数及文件名
boxplot(iris[,1]~iris[,5])
text(6.5,4, labels = 'hello')#作图代码
dev.off()#关闭画板
p <- ggboxplot(iris, x = "Species",
y = "Sepal.Length",
color = "Species",
shape = "Species",
add = "jitter")
ggsave(p,filename = "iris_box_ggpubr.png")
ggsave("iris_box_ggpubr.png")
library(eoffice)
topptx(p,"iris_box_ggpubr.pptx")
引用自生信技能树 小洁老师
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。