ggplot2 plusieurs geom_point dans un seul tracé
Sep 30 2020
Je veux visualiser la relation de yavec A, Bet Cséparément sur 10 niveaux d'une groupvariable en utilisant geom_point().
Mon tracé actuel ne peut tracer ycontre Amais je veux Bet Cà afficher dans chaque parcelle dans des couleurs différentes.
Je me demandais comment cela pourrait être réalisable ggplot2?
library(ggplot2)
dat <- read.csv('https://raw.githubusercontent.com/rnorouzian/e/master/sng.csv')
ggplot(dat)+aes(x=A, y = y, fill = group)+geom_point()+ # How can I have `B` and `C` next to `A` with other colors
facet_wrap(~group)
Réponses
2 RonakShah Sep 30 2020 at 11:32
Essayez la méthode standard: obtenir les données au format long.
library(ggplot2)
dat %>%
tidyr::pivot_longer(cols = A:C) %>%
ggplot()+aes(x=value, y = y, color = name) +
geom_point() + facet_wrap(~group)
1 akrun Oct 01 2020 at 06:26
Nous pouvons utiliser ggscatterdeggpubr
library(ggpubr)
library(purrr)
ggscatter(dat, x = c("A", "B", "C"), y = "y", color = "group", palette = "jco") %>%
invoke(ggarrange, ., ncol = 2, nrow = 2)
-production