特殊语法:列名不加引号,行末带加号
映射:根据数据的某一列的内容设置颜色
手动设置:把图形设置为一个或n个颜色,与数据内容无关
首先要有映射,并且根据映射的类型数给出颜色数。
颜色:英文单词;十六进制颜色代码
Q2.1 空心形状和实心形状都用color设置颜色
Q2.2 既有边框又有内心,既有color又有fill
用来分面的列:若干个并列的值,分类型的变量;分面的个数是有限的
双分面:
不要修改内置数据!
library(ggplot2)
ggplot(data = iris)+
geom_point(mapping = aes(x = Sepal.Length,
y = Petal.Length,
color = Species))+
scale_color_manual(values = c("blue","red","grey"))
a = c("blue","red","grey")
names(a) = unique(iris$Species)
ggplot(data = iris)+
geom_point(mapping = aes(x = Sepal.Length,
y = Petal.Length,
color = Species))+
scale_color_manual(values = a)
有y就必须加stat='identity'
用..prop..来与列名进行区分
library(ggpubr)
ggboxplot(iris,x = "Species",y = "Sepal.Width",fill = 'Species')+
geom_point()
ggboxplot(iris,x = "Species",y = "Sepal.Width",fill = 'Species')+
geom_jitter() #避免重叠
ggplot(data = iris,mapping = aes(x = Sepal.Width,
y = Species))+
geom_violin(mapping = aes(fill=Species))+
geom_boxplot()+
geom_jitter(mapping = aes(shape=Species)) #要有映射
dev.off() #关闭画板,报错也没问题,如果多次运行也不出图就dev.new()
保存不同类型的图片文件:
pdf(file = "p.pdf",width =12,height = 9)
print(p)
dev.off()
png(filename = "p.png",width = 1200,height = 900,res = 300)
print(p)
dev.off()
ggplot
ggsave(p,filename = "p.pdf",width = 12,height = 9)
ggsave(p,filename = "p.png",width = 12,height = 9)
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。