Ggplot with full data and subset (s) along the x axis

I will use scripted graphs as an example, but the question extends to many other types of ggplot.

I know how to multiply my x-axis data at one time:

ggplot(iris, aes(x = Species, y = Sepal.Length)) +
  geom_violin() +
  geom_point(position = "jitter")

violin by type

And I know how to build only a complete data set:

ggplot(iris, aes(x = 1, y = Sepal.Length)) +
  geom_violin() +
  geom_point(position = "jitter")

full image of violin

My question is: is there a way to build complete data and a subset individually in the same plot? In other words, for the diaphragm data, could I make a violin plot that has both โ€œfull dataโ€ and โ€œsetoseโ€ along the x axis?

This will allow you to compare the distribution of the full data set and a subset of this data set. If this is not possible, any recommendations on a better way to visualize this would also be welcome :)

Thanks for any ideas!

+4
1

:

ggplot(iris, aes(x = "All", y = Sepal.Length)) +
  geom_violin() +
  geom_point(aes(color="All"), position = "jitter") +
  geom_violin(data=iris, aes(x = Species, y = Sepal.Length)) +
  geom_point(data=iris, aes(x = Species, y = Sepal.Length, color = Species), 
             position = "jitter") +
  scale_color_manual(values = c("black","#F8766D","#00BA38","#619CFF")) +
  theme_minimal(base_size = 16) +
  theme(axis.title.x = element_blank(), legend.title = element_blank())

:

enter image description here

+8

Source: https://habr.com/ru/post/1616075/


All Articles