
#作图分三类
plot(iris[,1],iris[,3],col = iris[,5])
text(6.5,4, labels = 'hello')
dev.off() #关闭画板library(ggplot2)
ggplot(data = iris)+
geom_point(mapping = aes(x = Sepal.Length,
y = Petal.Length,
color = Species))library(ggpubr)
ggscatter(iris,
x="Sepal.Length",
y="Petal.Length",
color="Species")library(ggplot2)#1.入门级绘图模板:作图数据,横纵坐标
ggplot(data = iris)+
geom_point(mapping = aes(x = iris[,1],
y = Petal.Length))ggplot(data = iris) +
geom_point(mapping = aes(x = Sepal.Length,
y = Petal.Length),
color = "red",
alpha = 0.4,
shape = iris[,4])
ggplot(data = iris) +
geom_point(mapping = aes(x = Sepal.Length, y = Petal.Length),
size = 5, # 点的大小5mm
alpha = 0.5, # 透明度 50%
shape = 8) # 点的形状ggplot(data = iris)+
geom_point(mapping = aes(x = Sepal.Length,
y = Petal.Length,
color = Species)) #color = Species是一种映射
#此处如果写color = "xxx" 结果是只会出来一种颜色,因为会认为只需要一种颜色
ggplot(data = iris)+
geom_point(mapping = aes(x = Sepal.Length,
y = Petal.Length,
color = Species))+
scale_color_manual(values = c("blue","grey","red")) #删除color=Species,这行代码无法改变颜色#想要什么颜色就有什么颜色-十六进制颜色编码
ggplot(data = iris)+
geom_point(mapping = aes(x = Sepal.Length,
y = Petal.Length,
color = Species))+
scale_color_manual(values = c("#2874C5","#e6b707","#f87669"))#paletteer-集成多个配色R包,两千多种选择
if(!require(paletteer))install.packages("paletteer",ask = F,update = F)
if(!require(awtools))install.packages("awtools",ask = F,update = F)
library(paletteer)
ggplot(data = iris)+
geom_point(mapping = aes(x = Sepal.Length,
y = Petal.Length,
color = Species))+
scale_color_paletteer_d("awtools::mpalette") #用别人R包里的配色
palettes_d_names
#View(palettes_d_names)ggplot(data = iris)+
geom_point(mapping = aes(x = Sepal.Length,
y = Petal.Length,
color = Species),
shape = 17) #17号,实心的例子
ggplot(data = iris)+
geom_point(mapping = aes(x = Sepal.Length,
y = Petal.Length,
color = Species),
shape = 2) #2号,空心的例子
### Q2-2 既有边框又有内心的,才需要color和fill两个参数
ggplot(data = iris)+
geom_point(mapping = aes(x = Sepal.Length,
y = Petal.Length),
shape = 24,
color = "red",
fill = "yellow") #24号,双色的例子 fill:里面填充的颜色 color:可能是实心也可能是空心#局部设置和全局设置
ggplot(data = iris) +
geom_smooth(mapping = aes(x = Sepal.Length,
y = Petal.Length))+ #此处为局部设置 仅对当前图层有效
geom_point(mapping = aes(x = Sepal.Length,
y = Petal.Length))
ggplot(data = iris,mapping = aes(x = Sepal.Length, y = Petal.Length))+ #此处为全局设置 对所有图层都生效
geom_smooth()+
geom_point()#抖动的点图
ggplot(data = iris,mapping = aes(x = Species,
y = Sepal.Width,
fill = Species)) +
geom_boxplot()+
geom_point()
ggplot(data = iris,mapping = aes(x = Species,
y = Sepal.Width,
fill = Species)) +
geom_boxplot()+
#geom_point(position = "jitter")
geom_jitter() #抖动图ggplot(data = iris,mapping = aes(x = Species,
y = Sepal.Width,
fill = Species)) +
geom_boxplot()+
geom_jitter()+
coord_flip() #翻转坐标系ggplot(data = iris,mapping = aes(x = Species,
y = Sepal.Width,
fill = Species)) +
geom_boxplot()+
geom_jitter()+
theme_bw() #简洁主题 theme_classiclibrary(ggpubr)
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,
aes(label = after_stat(p.signif))) #分布叠加 aes里面的函数:显示显著性#1.基础包作图的保存
pdf("iris_box_ggpubr.pdf")
boxplot(iris[,1]~iris[,5])
text(6.5,4, labels = 'hello')
dev.off()#2.ggplot系列图(包括ggpubr)通用的简便保存 ggsave
p <- ggboxplot(iris, x = "Species",
y = "Sepal.Length",
color = "Species",
shape = "Species",
add = "jitter")
ggsave(p,filename = "iris_box_ggpubr.png")devtools::install_github("guokai8/eoffice")
devtools::install_github("davidgohel/rvg")
BiocManager::install("davidgohel/rvg")
library(eoffice)
topptx(p,"iris_box_ggpubr.pptx")#完美兼容ggplot2
#支持直接p1+p2拼图,复杂布局代码易读性更强
#可以给子图添加标记
#可以统一修改子图
#可以将子图的图例移到一起,整体性好
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。