简体   繁体   English

使 geom_jitter 点变粗

[英]Make geom_jitter points thicker

I am trying to adjust the thickness of geom_jitter points in ggplot without increasing the overall size.我正在尝试在不增加整体大小的情况下调整 ggplot 中 geom_jitter 点的厚度。

Here is what I currently have:这是我目前拥有的:

data <- data.frame(A=c(1,2,3,4,5,6,7,8,9), B=c(7,8,9,4,3,5,4,3,2))

p <- ggplot(data, aes(A, B))

p + geom_jitter(pch=4, cex=8, lwd=3)

The script runs if I do not include the lwd option, but this appears to be what I am looking for to control the line width.如果我不包含lwd选项,脚本就会运行,但这似乎是我正在寻找的控制线宽的方法。 If I include it I get a warning message: Duplicated aesthetics after name standardisation: size .如果我包含它,我会收到一条警告消息: Duplicated aesthetics after name standardisation: size Based on this I'm guessing cex and lwd are being interpreted as doing the same thing, which doesn't seem right to me.基于此,我猜cexlwd被解释为做同样的事情,这对我来说似乎不正确。

How can I control for the overall size of the point (via cex), but change the thickness of the lines?如何控制点的整体大小(通过 cex),但改变线条的粗细?

The ggplot2 package doesn't specify properties of points the same way that base R plots do (though it makes an effort to translate). ggplot2 package 没有像基础 R 绘图那样指定点的属性(尽管它努力翻译)。 Here is a ggplot-esque way of specifying the thickness of lines ( stroke ).这是一种 ggplot 式的指定线条粗细( stroke )的方法。

library(ggplot2)

data <- data.frame(A=c(1,2,3,4,5,6,7,8,9), B=c(7,8,9,4,3,5,4,3,2))

p <- ggplot(data, aes(A, B))

p + geom_jitter(shape=4, size=8, stroke=3)

Created on 2021-03-12 by the reprex package (v0.3.0)代表 package (v0.3.0) 于 2021 年 3 月 12 日创建

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM