Plot Zoom with R

huangapple go评论91阅读模式
英文:

Plot Zoom with R

问题

早上好,
我需要放大以下的图表。

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)

结果如下:

Plot Zoom with R

这段代码从"A"缩放到"B",但我想要放大所有的估算器"A"和"B"。换句话说,我不希望盒图在缩放时被裁剪。我尝试过使用facet_zoom(),但结果更糟糕。

谢谢。

英文:

Good morning,
I have to zoom in the following plot.

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)

The result is:

Plot Zoom with R

This code zoom from "A" to "B" but i'd like to zoom in all the estimator "A" and "B". In other words I wouldn't want that the boxplot was cuted in the zoom. I try also with facet_zoom() but the result is even wrose.

Thank you.

答案1

得分: 1

这是你需要的吗?可能是调整对 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(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)

Plot Zoom with R

创建于2023-06-26,使用 reprex v2.0.2

英文:

Is this what you are after? Possibly a matter of adjusting the parameters of the call to 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)

Plot Zoom with R<!-- -->

<sup>Created on 2023-06-26 with reprex v2.0.2</sup>

huangapple
  • 本文由 发表于 2023年6月26日 16:16:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/76554789.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定