Plot Zoom with R

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

Plot Zoom with R

问题

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

  1. times=data.frame("Times"=c(sample(seq(0, 1, 0.01),1000, replace = TRUE), sample(c(40:70), 500, replace = TRUE)),
  2. "Estimator"=rep(c("A", "B", "C"), each=500))
  3. library(ggmagnify)#GitHub library
  4. library(ggplot2)
  5. library(PupillometryR)
  6. times %>%
  7. ggplot() +
  8. aes(x = Estimator,
  9. y = Times) +
  10. geom_point(aes(color = Estimator),
  11. position = position_jitter(w = .15),
  12. size = 0.5,
  13. alpha = 0.15) +
  14. geom_boxplot(width = .24,
  15. outlier.shape = NA,
  16. alpha = 0.5) +
  17. geom_flat_violin(position = position_nudge(x = .2),
  18. trim = TRUE,
  19. alpha = 1,
  20. scale = "width") +
  21. scale_fill_manual(values = c("#00AFBB", "#E7B800", "#FC4E07"))+
  22. coord_flip()+geom_magnify(aes(from = Estimator != "A" | Estimator == "B"), to = c(1, 2, 20, 30),
  23. shape = "ellipse", shadow = F)

结果如下:

Plot Zoom with R

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

谢谢。

英文:

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

  1. times=data.frame("Times"=c(sample(seq(0, 1, 0.01),1000, replace = TRUE), sample(c(40:70), 500, replace = TRUE)),
  2. "Estimator"=rep(c("A", "B", "C"), each=500))
  3. library(ggmagnify)#GitHub library
  4. library(ggplot2)
  5. library(PupillometryR)
  6. times%>%
  7. ggplot() +
  8. aes(x =Estimator ,
  9. y = Times) +
  10. geom_point(aes(color = Estimator),
  11. position = position_jitter(w = .15),
  12. size = 0.5,
  13. alpha = 0.15) +
  14. geom_boxplot(width = .24,
  15. outlier.shape = NA,
  16. alpha = 0.5) +
  17. geom_flat_violin(position = position_nudge(x = .2),
  18. trim = TRUE,
  19. alpha = 1,
  20. scale = "width") +
  21. scale_fill_manual(values = c("#00AFBB", "#E7B800", "#FC4E07"))+
  22. coord_flip()+geom_magnify(aes(from = Estimator != "A" | Estimator == "B"), to = c(1, 2, 20, 30),
  23. 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 的调用参数的问题。

  1. set.seed(123)
  2. times=data.frame("Times"=c(sample(seq(0, 1, 0.01), 1000, replace = TRUE),
  3. sample(c(40:70), 500, replace = TRUE)),
  4. "Estimator"=rep(c("A", "B", "C"), each = 500))
  5. library(ggmagnify)#GitHub
  6. library(ggplot2)
  7. library(PupillometryR)
  8. times |>
  9. ggplot() +
  10. aes(x =Estimator ,
  11. y = Times) +
  12. geom_point(aes(color = Estimator),
  13. position = position_jitter(w = .15),
  14. size = 0.5,
  15. alpha = 0.5) +
  16. geom_boxplot(width = .24,
  17. outlier.shape = NA,
  18. alpha = 0.5) +
  19. geom_flat_violin(position = position_nudge(x = .2),
  20. trim = TRUE,
  21. alpha = 1,
  22. scale = "width") +
  23. scale_fill_manual(values = c("#00AFBB", "#E7B800", "#FC4E07")) +
  24. coord_flip() +
  25. geom_magnify(from = c(0.5, 3, -1, 2),
  26. to = c(0.5, 3, 10, 30),
  27. shape = "ellipse",
  28. 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.

  1. set.seed(123)
  2. times=data.frame("Times"=c(sample(seq(0, 1, 0.01), 1000, replace = TRUE),
  3. sample(c(40:70), 500, replace = TRUE)),
  4. "Estimator"=rep(c("A", "B", "C"), each = 500))
  5. library(ggmagnify)#GitHub library
  6. library(ggplot2)
  7. library(PupillometryR)
  8. times |>
  9. ggplot() +
  10. aes(x =Estimator ,
  11. y = Times) +
  12. geom_point(aes(color = Estimator),
  13. position = position_jitter(w = .15),
  14. size = 0.5,
  15. alpha = 0.5) +
  16. geom_boxplot(width = .24,
  17. outlier.shape = NA,
  18. alpha = 0.5) +
  19. geom_flat_violin(position = position_nudge(x = .2),
  20. trim = TRUE,
  21. alpha = 1,
  22. scale = "width") +
  23. scale_fill_manual(values = c("#00AFBB", "#E7B800", "#FC4E07")) +
  24. coord_flip() +
  25. geom_magnify(from = c(0.5, 3, -1, 2),
  26. to = c(0.5, 3, 10, 30),
  27. shape = "ellipse",
  28. 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:

确定