'Plotting multiple wordcloud (ggwordcloud) with other types of plots in ggplot2
I am trying to plot several wordclouds in a scatterplot and I wonder if one can control the position of a wordcloud in ggplot? As an example the code below overlays both wordclouds around the origin of the plot. Say I want to place the second wordcloud at x=4 and y =35. Is that possible?
library(ggplot2)
library(ggwordcloud)
ggplot() +
geom_point(mtcars,mapping=aes(wt,mpg)) +
geom_text_wordcloud(love_words_small,mapping=aes(label=word)) +
geom_text_wordcloud(mtcars,mapping=aes(label=rownames(mtcars))) +
theme_minimal()
Solution 1:[1]
I was looking for the exact same thing. Looks like you can simply add the x and y aesthetic arguments. Ie.
ggplot() +
geom_point(mtcars,mapping=aes(wt,mpg)) +
geom_text_wordcloud(love_words_small,mapping=aes(label=word)) +
geom_text_wordcloud(mtcars,mapping=aes(label=rownames(mtcars), x=4,y=35)) +
theme_minimal()
What I did may be more generally helpful for folks, which is to pass x and y vectors:
library(tidyverse)
library(ggwordcloud)
ggplot(data = mtcars %>% mutate(car_names = rownames(mtcars)) %>%
group_by(cyl),
mapping = aes(label=car_names, x=mpg, y=disp)) +
geom_text_wordcloud()
Solution 2:[2]
Perhaps you could save the wordclouds as separate plots, and then add them to one plot with cowplot
or gridExtra
or any of the packages that lets you combine plots?
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 | |
Solution 2 | shogenboom |