簡體   English   中英

geom_jitter 點大於定義值的小提琴 plot

[英]Violin plot with geom_jitter dots greater than a defined value

我想創建一個 geom_jitter 點大於定義值的小提琴 plot。

下面是我用盒子plot和geom_jitter獲取數據點的這把小提琴plot的圖片和代碼。 有沒有辦法讓點 >58 的 geom_jitter 隱藏所有 rest?

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")

為了清晰起見,我將抖動的點塗成藍色。

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM