解决ggplot绘制散点图形状超过6个的警告

正常画图:

library(ggplot2)
ggplot(mpg,aes(displ,hwy))+geom_point(aes(shape=class,color=class))

在这里插入图片描述
可以看出形状少了一个,SUV没有形状
并且还会弹出这样的警告:

Warning message:
“The shape palette can deal with a maximum of 6 discrete values because
more than 6 becomes difficult to discriminate; you have 7. Consider
specifying shapes manually if you must have them.”
Warning message:
“Removed 62 rows containing missing values (geom_point()).”
警告消息: “形状调色板最多可以处理6个离散值,因为超过6个将很难区分; 您有7个。如果必须使用形状,可以考虑手动指定。”警告消息: “删除了包含丢失值(‘ geom _ point ()’)的62行。

解决方法:
ggplot中有如下这些形状:我们只要自定义自己需要的形状就行了自己
比如我使用1-7这7个形状

library(ggplot2)
ggplot(mpg,aes(displ,hwy))+
geom_point(aes(shape=class,color=class))+
   scale_shape_manual(values = c(1:7))

在这里插入图片描述

参考文章

R语言-ggplot自定义点的形状、线条的类型
ggplot2绘图点的形状不够用怎么办?

猜你喜欢

转载自blog.csdn.net/qq_54423921/article/details/127931449