1.基础包-绘图函数
实例
plot(iris ,1 ,iris,3,col = iris,5) text(6.5,4, labels = 'hello')
library(ggplot2)
ggplot(data = iris)+
geom_point(mapping = aes(x = Sepal.Length, y = Petal.Length,color = Species))
ggplot(data = <DATA>)+<GEOM_FUNCTION>(mapping = aes(<MAPPINGS>)
ggplot(data = iris)+geom_point(mapping = aes(x = Sepal.Length, y = Petal.Length))
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))
ggplot(data = iris)+
geom_point(mapping = aes(
x = Sepal.Length,
y = Petal.Length,
color = Species))+
scale_color_manual(values = c("blue","grey","red"))
ggplot(data = iris)+
geom_point(mapping = aes(
x = Sepal.Length,
y = Petal.Length,
color = Species))+
scale_color_brewer(palette = "Set1")
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号,空心的例子
ggplot(data = iris)+
geom_point(mapping = aes(
x = Sepal.Length,
y = Petal.Length,
color = Species),
shape = 24,
color="red",
fill = "yellow") #24号,双色的例子
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_jitter()
#geom_point(position = "jitter")
ggplot(data = iris,mapping = aes(x = Species,
y = Sepal.Width,
fill = Species)) +
geom_boxplot()+
geom_jitter()+
coord_flip()
theme_bw()
3.ggpubr #新手友好型 ggplot2简化和美化 褒贬不一
library(ggpubr)
ggscatter(iris,x="Sepal.Length", y="Petal.Length",color="Species")
library(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)))
ggplot2系列
ggsave("iris_box_ggpubr.png")
ggsave(p,filename="iris_box_ggpubr2.png")
通用:三段论
保存的函数及文件名 pdf("test.pdf")
作图代码 ...........
画完了,关闭画板 dev.off( )
p <- ggboxplot(iris, x = "Species",
y = "Sepal.Length",
color = "Species",
shape = "Species",
add = "jitter")
ggsave(p,filename = "iris_box_ggpubr.png")
library(eoffice)
topptx(p,"iris_box_ggpubr.pptx")
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。