'How do i replicate these plots using ggplot?
This is what I have tried so far. The box plot is kind of close, but the other plot is way off.
ggplot(data_anova, aes(x = delay, y = soa, color = age)) +
geom_jitter() +
geom_line(position=position_jitter(w=0, h=0)) +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"), legend.position = "none") +
labs(x = "SoA",
y = "delay")
ggplot(df, aes(x = age, y = soa, fill = age)) +
geom_boxplot() +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"), legend.position = "none") +
labs(x = "age",
y = "pse")
data
structure(list(age = c(1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 1L, 0L, 1L, 1L, 0L, 1L, 0L, 0L, 0L, 1L, 0L), sex = c("f", "m", "m", "f", "f", "f", "f", "m", "m", "m", "m", "f", "f", "m", "f", "m", "m", "f", "f", "f", "m", "f", "m", "f"), soa = c(0.1, 0.01, 0.8, 0.41, 0.86, 0.58, 0.43, 0.73, 0.23, 0.88, 0.73, 0.15, 0.66, 0.53, 0.64, 0.28, 0.47, 0.84, 0.93, 0.41, 0.23, 0.59, 0.64, 0.36), delay = c(100L, 100L, 100L, 200L, 200L, 200L, 300L, 300L, 300L, 400L, 400L, 400L, 500L, 500L, 500L, 600L, 600L, 600L, 700L, 700L, 700L, 800L, 800L, 800L)), class = "data.frame", row.names = c(NA, -24L))
Solution 1:[1]
For a start, something for your panel A:
ggplot(df, aes(x = delay, y = soa, color = sex)) +
geom_point(pch=21, size = 2.5) +
geom_smooth(method = "loess", se = F) +
ggplot2::scale_y_continuous(breaks = seq(0, 1, 0.1), limits = c(0,1))+
theme_minimal() +
labs(x = "Delay time [ms]",
y = "'Yes' response [ratio]",
color = "") +
scale_color_manual(labels = c("Children", "Young Adults"), values = c("blue", "red")) +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"),
legend.position = c(.19,.15),
panel.border = element_rect(colour = "black", fill=NA, size=2))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Julian |
