使用R缩放绘图

5f0d552i  于 2023-06-27  发布在  其他
关注(0)|答案(1)|浏览(137)

早上好,我得放大下面的情节。

times=data.frame("Times"=c(sample(seq(0, 1, 0.01),1000, replace = TRUE), sample(c(40:70), 500, replace = TRUE)), 
                 "Estimator"=rep(c("A", "B", "C"), each=500))

library(ggmagnify)#GitHub library
library(ggplot2)
library(PupillometryR)
times%>%
ggplot() +
  aes(x =Estimator ,
      y = Times) +
  geom_point(aes(color = Estimator),
             position = position_jitter(w = .15),
             size = 0.5,
             alpha = 0.15) +
  geom_boxplot(width = .24,
               outlier.shape = NA,
               alpha = 0.5) +
  geom_flat_violin(position = position_nudge(x = .2),
                   trim = TRUE, 
                   alpha = 1, 
                   scale = "width")  +
  scale_fill_manual(values = c("#00AFBB", "#E7B800", "#FC4E07"))+
  coord_flip()+geom_magnify(aes(from = Estimator != "A" | Estimator == "B"),  to = c(1, 2, 20, 30), 
                            shape = "ellipse", shadow = F)

结果是:

这段代码从“A”到“B”缩放,但我想放大所有的估计器“A”和“B”。换句话说,我不希望箱线图在缩放时被切断。我也尝试使用facet_zoom(),但结果甚至是扭曲的。
谢谢你。

bxpogfeg

bxpogfeg1#

这就是你想要的吗可能是调整ggmagnify调用的参数的问题。

set.seed(123)

times=data.frame("Times"=c(sample(seq(0, 1, 0.01), 1000, replace = TRUE), 
                           sample(c(40:70), 500, replace = TRUE)), 
                 "Estimator"=rep(c("A", "B", "C"), each = 500))

library(ggmagnify)#GitHub library
library(ggplot2)
library(PupillometryR)

times |> 
  ggplot() +
  aes(x =Estimator ,
      y = Times) +
  geom_point(aes(color = Estimator),
             position = position_jitter(w = .15),
             size = 0.5,
             alpha = 0.5) +
  geom_boxplot(width = .24,
               outlier.shape = NA,
               alpha = 0.5) +
  geom_flat_violin(position = position_nudge(x = .2),
                   trim = TRUE, 
                   alpha = 1, 
                   scale = "width") +
  scale_fill_manual(values = c("#00AFBB", "#E7B800", "#FC4E07")) +
  coord_flip() +
  geom_magnify(from = c(0.5, 3, -1, 2),  
               to = c(0.5, 3,  10, 30), 
               shape = "ellipse",
               shadow = F)

创建于2023-06-26带有reprex v2.0.2

相关问题