英文:
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)
结果如下:
这段代码从"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:
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)
创建于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)
<!-- -->
<sup>Created on 2023-06-26 with reprex v2.0.2</sup>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论