使用ggplot2修改点的子集的形状 [英] Modifying the shape for a subset of points with ggplot2

查看:1685
本文介绍了使用ggplot2修改点的子集的形状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图绘制沿大量维度变化的大散点图。

I'm attempting to plot a large scatter plot that varies along a large number of dimensions.

以下是我的出发情节:

Here's my starting plot:

 p <- ggplot(mtcars, aes(wt, mpg, shape=cyl, colour=gear, size=carb)) +
      geom_point()

使用 mtcars 数据集,我只是简单地包含各种形状,颜色和大小。现在我想补充一点是,在碳八= 8的所有点周围都有一些显着的标记。例如,围绕这些点添加一个大黑圈。

Using the mtcars dataset, I'm simply including various shapes, colours, and sizes. Now what i'd like to add to this is some distinguishing mark around all points with carb==8. For example, add in a big black circle around these points.

正在做

p + geom_point() + geom_point(colour="black", shape=1, size=5)

很接近,因为它可以像我想要的那样得到圆圈,但是所有的点都会得到圆圈,我想将它限制在一些点上。

is close in that it gets the circles as I want, but all points get circles, I want to instead limit this to just some of the points.

我将不胜感激这个问题的任何建议。

I would greatly appreciate any suggestions for this problem.

推荐答案

而不是最初把ggplot函数中的变量,尝试映射你的

Instead of initially putting your variables within the ggplot function, try to map your variables individually for every layer you add.

p <- ggplot(data = mtcars)+
geom_point(aes(wt, mpg, shape=as.factor(cyl), colour=gear, size=carb))+
geom_point(aes(wt[carb==8], mpg[carb==8]), colour="black", shape=1, size=7)  

这篇关于使用ggplot2修改点的子集的形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆