r - geom_jitter 点大于定义值的小提琴图
问题描述
我想创建一个 geom_jitter 点大于定义值的小提琴图。
下面是我用来获取此小提琴图的图片和代码,其中包含箱形图和数据点的 geom_jitter。有没有办法让超过 58 的点的 geom_jitter 并隐藏所有其余部分?
library(nycflights13)
library(ggplot2)
library(dplyr)
weather3 <- weather %>%
filter(month == 3)
viol_plot <- ggplot(weather3, aes(x = factor(month), y = temp)) +
geom_violin()
viol_plot + geom_boxplot(width=0.2) + geom_jitter(shape=20, position = position_jitter(0.05))
viol_plot + geom_jitter(shape=20, position = position_jitter(0.05))
谢谢!
解决方案
只需将数据geom_jitter()
与 ggplot 定义的原始定义分开定义即可。
weather3 <- weather %>%
filter(month == 3)
viol_plot <- ggplot(weather3, aes(x = factor(month), y = temp)) +
geom_violin()
viol_plot + geom_boxplot(width=0.2) +
geom_jitter(data=weather3[weather3$temp>58,], shape=20, position = position_jitter(0.05), color="blue")
为了清晰起见,我将抖动的点涂成蓝色。
推荐阅读
- docusignapi - 什么可以用作自定义电子邮件资源文件中的合并字段 [[Data: ]] 值
- python - 为什么有第二个变量指向 map() 函数,变量 student 来自哪里
- java - 无法反序列化 java.time.OffsetDateTime
- node.js - Node.js:检查 path.format() 的根
- reactjs - 可以不用 useImperativeHandle 钩子来完成吗
- asp.net - 二进制文件未在 Radgrid 中加载
- android - 如何在 Kotlin 中创建包含 n 个元素的 ArrayList?
- css - 从 devtools 粘贴 CSS 会创建多行
- go - 在 golang 上使用 julien schmidt http 路由器时,Swagger 给出 404 not found 错误
- symfony - 如何从自定义供应商包中提取翻译