Camilo
Camilo

Reputation: 449

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()

Upvotes: 0

Views: 596

Answers (2)

Marcus Lehr
Marcus Lehr

Reputation: 57

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()

Upvotes: 1

shogenboom
shogenboom

Reputation: 11

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?

Upvotes: 0

Related Questions